Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: system() requires double ctrl-c

by ikegami (Patriarch)
on Nov 10, 2008 at 08:14 UTC ( [id://722577]=note: print w/replies, xml ) Need Help??


in reply to system() requires double ctrl-c

For people that do error checking, it's not a problem.
die if system("some_long_running_shell_command");

Update: I had the condition negated, as pointed out in replies. Fixed.

Replies are listed 'Best First'.
Re^2: system() requires double ctrl-c
by JavaFan (Canon) on Nov 10, 2008 at 11:24 UTC
    That may not always work; it depends what the return value of some_long_running_shell_command is when it receives a SIGINT. And it also depends what it returns when no SIGINT is given. "find" for instance returns (shell) FALSE on SIGINT, but also FALSE when it cannot process all files (for instance when the process doesn't have permission to decent into a directory). And (at least the 'find' found on my computer) it doesn't specify the actual exit values; just 0 and non-0.

    So, checking return values may work, but be aware, it will depend on the actual command run whether it will.

Re^2: system() requires double ctrl-c
by saintmike (Vicar) on Nov 10, 2008 at 08:40 UTC
    For people that do error checking, it's not a problem. die if !system("some_long_running_shell_command");
    You mean die if system(...) as system returns 0 on success ... ok, this works for simple scripts, but in the general case you might want the script to handle the error instead of dying.

      Oops! So used to "if!" or "or" to catch errors. Fixed.

      As for the simplicity, it was just an example. You're right that it's really not suitable for use. The docs for system provide a more complete example.

Re^2: system() requires double ctrl-c
by jwkrahn (Abbot) on Nov 10, 2008 at 08:44 UTC

    system returns TRUE on error so you are dieing if system("some_long_running_shell_command") executed successfully.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 06:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found