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

Re: qx and $!

by helgi (Hermit)
on Oct 20, 2006 at 11:10 UTC ( #579549=note: print w/ replies, xml ) Need Help??


in reply to qx and $!

A comparison on how to run external programs and get meaningful errors from them:

print qx(date) or die "Cannot run date:$!\n"; system (date) == 0 or die "Cannot run date:$?\n";

--
Regards,
Helgi Briem
hbriem AT f-prot DOT com


Comment on Re: qx and $!
Download Code
Re^2: qx and $!
by ikegami (Pope) on Oct 29, 2006 at 20:19 UTC

    That's not right.

    • Both qx and system set $! when unable to launch the child.
    • Both qx and system set $? to the child's error code.
    • An error did not necessarily occur when qx return false, only when it returns undef.
    • $! is not necessarily set when qx return false, only when it returns undef.

    Here is how one actually gets meaningful errors from them:

    my $output = qx(date); die("Unable to launch external process: $!\n") if not defined $output; die("The external process did not run successfully (error code $?)\n") if $?;
    my $rv = system(date); die("Unable to launch external process: $!\n") if $rv == -1; die("The external process did not run successfully (error code $?)\n") if $?;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2015-07-07 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls