Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: qx and $!

by helgi (Hermit)
on Oct 20, 2006 at 11:10 UTC ( [id://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

Replies are listed 'Best First'.
Re^2: qx and $!
by ikegami (Patriarch) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://579549]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-25 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found