Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: How to skip to next Command line

by Perl Mouse (Chaplain)
on Jan 25, 2006 at 09:35 UTC ( #525390=note: print w/replies, xml ) Need Help??


in reply to Re: How to skip to next Command line
in thread How to skip to next Command line

The problem with that solution is that if the fork fails, block.exe will be executed, but the rest of the program won't. Also, system returns false if the command was succesful, and any error status is in $?, not $!.

A better way would be:

my $pid = fork; die "Fork failed: $!" unless defined $pid; unless ($pid) { system "C:\\block.exe"; die "Command failed with exit code ", $? >> 8 if $?; exit; } print "processing second line...\n";
Or, if you don't want to handle failures of block.exe in your program:
my $pid = fork; die "Fork failed: $!" unless defined $pid; unless ($pid) { exec "C:\\block.exe"; die "exec failed: $!"; } print "processing second line...\n";
Perl --((8:>*

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://525390]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2020-10-20 00:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (208 votes). Check out past polls.

    Notices?