in reply to Multiple commands with one system call

I know I could use the exec() call to start the program and then proceed to run the rest of my commands.

No. That's not how exec works - it replaces the location that perl is running with the specified system command. This means any code after an exec is dead code.

You may get your expected result with something closer to:

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

Short of that, you'd probably need some sort of daemon, which is likely far more sledge than this hammer needs.

Replies are listed 'Best First'.
Re^2: Multiple commands with one system call
by Anonymous Monk on Sep 29, 2011 at 19:19 UTC

    I would perhaps try this:

    if (system(qw/vp -e/, $ENV{VREL}) != 0) { # last command failed system(qw/vscmd set-measure-mode fast/); system(qw/vscmd pg-address-check off/); }

    I'm not sure which program gets the ctrl-C, but if it's not the Perl script, that should work.

Re^2: Multiple commands with one system call
by renzosilv (Novice) on Sep 29, 2011 at 14:49 UTC

    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!

      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.