Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

how do i execute dependant system commands in perl (i m trying waitpid but does not work) - please help

by sdj (Initiate)
on Jan 27, 2012 at 10:15 UTC ( [id://950307]=perlquestion: print w/replies, xml ) Need Help??

sdj has asked for the wisdom of the Perl Monks concerning the following question:

Hi i am executing two commands from my perl script.
1. zcat ... | gzip huge file. &
it takes lots of time
2. java huge file &
after above 1. is done.
how can i do this?
here is what I am doing but does not work:

system("zcat....> file1 &"); my $pid = fork(); waitpid($pid,0); system("java file1 &");

idea is : i want to execute java file1 after zcat is done
Please help.
Thanks,
SDJ

  • Comment on how do i execute dependant system commands in perl (i m trying waitpid but does not work) - please help
  • Download Code

Replies are listed 'Best First'.
Re: how do i execute dependant system commands in perl (i m trying waitpid but does not work) - please help
by GrandFather (Saint) on Jan 27, 2012 at 10:21 UTC

    In what way doesn't it work? system already waits for the executed command to complete so you shouldn't need anything more than:

    system("zcat....> file1 &"); system("java file1 &");

    to have the commands run one after the other.

    True laziness is hard work
      system already waits for the executed command to complete

      Don't the ampersands on the ends of those commands mean that the command processes will be backgrounded by the shell and system will return immediately?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        Argh! Quite right - I didn't notice them. :(

        In fact that will be why it "doesn't work" for the OP. Probably a little cargo culting going on.

        True laziness is hard work
Re: how do i execute dependant system commands in perl (i m trying waitpid but does not work) - please help
by ikegami (Patriarch) on Jan 27, 2012 at 22:00 UTC

    & does exactly the opposite of what you want. It causes the shell to not wait for its child to finish.

    system is basically fork+exec+waitpid mixed into one.

    system("zcat....> file1"); system("java file1");

    Or if you don't want to wait for java to finish,

    system("( zcat....> file1 && java file1 )&");
Re: how do i execute dependant system commands in perl (i m trying waitpid but does not work) - please help
by fisher (Priest) on Jan 27, 2012 at 10:27 UTC
    just don't fork(), system() will not return control until job's done.
Re: how do i execute dependant system commands in perl (i m trying waitpid but does not work) - please help
by i5513 (Pilgrim) on Jan 27, 2012 at 15:40 UTC

    Play with sh !

    system ("(zcat ... > file1 & wait; java file1)&"); your next sentence;
    Now you need to know when java process end .., but it should be another question, right ?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://950307]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-23 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found