in reply to How to skip to next Command line
system waits for its external command to complete. If you want to continue executing the script oblivious of the progress of the system call, you will have to fork off your system call. Here's a cheap and dirty example:
if( fork() == 0 ) { system( "C:\\block.exe" ) or die "Command failed: $!\n"; exit; } print "processing second line...\n";
It's important to keep track of who is the parent and who is the child. fork() returns '0' to the child process, and the child process's ID to the parent. So the if(){} test I've used detects whether a given process is the child (in which case it executes the system command and then exits), or the parent (in which case it continues on to the next line). I could have used exec instead of system, but wanted to provide a way to gracefully handle external command failure. See fork, perlfork, and in a broader sense, perlipc for additional info and discussion of some of the fork pitfalls and handling processes.
Dave
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to skip to next Command line
by Perl Mouse (Chaplain) on Jan 25, 2006 at 09:35 UTC |