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

Dear Folks
I have several system calls, each one depends on the previous, I am using the command 'system(<cmd>') -

system(<cmd1>); system(<cmd2>); system(<cmd3>);

and I would like to prevent them to run in the background. does 'exec' will help me or there is any other way to execute the command one after the other. Any examples ?

thanks in advance azaria

Update: I call serially c++ programs, each one cannot start until the previous completed, so i might need to have a code that wait .. any trick ?

20080520 Janitored by Corion: Restored original content

Replies are listed 'Best First'.
Re: serial system executions
by toolic (Bishop) on May 09, 2008 at 20:59 UTC
    According to the documentation for exec:
    The "exec" function executes a system command and never returns -- use "system" instead of "exec" if you want it to return.

    So, system should run each simple command serially, and wait for each to finish. For example:

    use warnings; use strict; system 'sleep 5' and die "ERROR: sleep died\n"; system 'echo hello > foo.txt' and die "ERROR: echo died\n"; system 'cat foo.txt' and die "ERROR: cat died\n";

    On my linux system, "sleep" executes, then "echo" then "cat".

      I run on windows for .exe (c++ program), each one of them are long' and does not wait each system(exe_cmd) to the previous. Any solution ? maybe while loop ?
Re: serial system executions
by blazar (Canon) on May 10, 2008 at 13:19 UTC

    I personally believe that everything is possible, but often enough if you have that many system commands to execute in series, then you probably want a shell script rather than a Perl script. YMMV.

    --
    If you can't understand the incipit, then please check the IPB Campaign.