in reply to Re: Multiple commands with one system call
in thread Multiple commands with one system call

Thanks for the correction, regarding exec(). Is always good to learn new things. :-)

The format you suggested doesn't work. It only takes the first command and it ignores the other two.

Thanks for the input though!

  • Comment on Re^2: Multiple commands with one system call

Replies are listed 'Best First'.
Re^3: Multiple commands with one system call
by kennethk (Abbot) on Sep 29, 2011 at 17:02 UTC
    Are you sure about that? When I execute:

    perl -e 'system("echo 1;echo 2;echo 3")'

    I get the output:

    1 2 3

    Are you interupting execution, with perhaps ^c? In this case, yes, you are killing all jobs simultaneously. You could execute all three by splitting into multiple system calls:

    system ("vp -e $ENV{VREL}"); system ("vscmd set-measure-mode fast; vscmd pg-address-check off");

      I think when you make the echo call. System calls echo 1 finishes and then calls echo 2. In my case however my first program doesn't finish, I actually have to make the second call while the first one is running. Which is what makes it a bit challenging since the second call will not happen until the first one is done.

        Then at the very least, you need a fork or threads. Depending on some very practical details, I would probably use IPC::Open2 to monitor progress of the child progress so you know when to execute your secondary commands. Some details of interprocess communication are discussed in perlipc.
        if Perl detects any shell meta-characters, it forks-and-exec a shell to handle the command. So you can jam a series of shell commands into your system() call. Note that I said "can", not "this is a good idea." ;)