Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: SIGINT in system() with shell metachars

by chip (Curate)
on Jun 24, 2003 at 23:48 UTC ( [id://268711]=note: print w/replies, xml ) Need Help??


in reply to SIGINT in system() with shell metachars

You could just temporarily ignore SIGINT just like C's system() does:

{ local $SIG{INT} = 'IGNORE'; $ret = system @whatever }

    -- Chip Salzenberg, Free-Floating Agent of Chaos

Replies are listed 'Best First'.
Re: Re: SIGINT in system() with shell metachars
by bunnyman (Hermit) on Jun 25, 2003 at 13:56 UTC
    Perl's system() already ignores SIGINT and SIGQUIT, as well as Perl's backticks. The question is how to get the correct return value back from system().
      Ah, quite so. You are up against a fug/beature in the shell, i.e. that when the shells spawns kids killed by a signal, the shell doesn't exit with a signal-like exit status.

      I suggest using the 'trap' shell statement to generate a non-standard exit status from signal delivery. There are some timing quirks that may hit you if the child is doing things like saving and restoring tty modes, but otherwise it works (I just tested it on Linux):

      system(q[ trap 'exit 77' 2; foo | bar ]); if (($? >> 8) == 77) { wow_i_got_a_sigint(); }

      The shell's 'trap' statement is a handy feature, seldom used.

          -- Chip Salzenberg, Free-Floating Agent of Chaos

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2024-04-23 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found