http://www.perlmonks.org?node_id=1002507


in reply to Launching multiple programs from Perl script

exec($cmd1) if fork; exec($cmd2) if fork; exec($cmd3) if fork;

Also FYI, exec doesn't cause your script to "die"; it removes your script from the operating system's process table, replacing it with the executed command. Thus your script "becomes" the executed program.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: Launching multiple programs from Perl script
by mbethke (Hermit) on Nov 06, 2012 at 17:12 UTC
    Just as short but makes for a more intuitive process relationship---all $cmdX processes are children of the script instead of $cmd3 being a child of $cmd2 which is a child of $cmd1:
    fork or exec $cmd1; fork or exec $cmd2; fork or exec $cmd3;
Re^2: Launching multiple programs from Perl script
by Shawrich (Initiate) on Nov 06, 2012 at 16:38 UTC
    I tested this but found the code stopped after the first exec statement. Here is the portion of my code I'm working with.
    foreach ( keys %bridges ) { if ( $bridges{$_} ) { my $cmdStr = "\"C:\\Some Path\\$_\\Some File.exe\""; exec($cmdStr) if fork; } }
      You mean the exec never returned? Strange. fork/exec emulation is not exactly straightforward on Windows but it shouldn't be that broken. Works fine here on Linux. Are you sure it's not how %bridges is set up?