FAQ 8.42 How do I make a system() exit on control-C?
am 27.08.2007 15:03:03 von PerlFAQ Server
This is an excerpt from the latest version perlfaq8.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
------------------------------------------------------------ --------
8.42: How do I make a system() exit on control-C?
You can't. You need to imitate the system() call (see perlipc for sample
code) and then have a signal handler for the INT signal that passes the
signal on to the subprocess. Or you can check for it:
$rc = system($cmd);
if ($rc & 127) { die "signal death" }
------------------------------------------------------------ --------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
--
Posted via a free Usenet account from http://www.teranews.com
Re: FAQ 8.42 How do I make a system() exit on control-C?
am 28.08.2007 21:11:08 von tk
On Aug 27, 3:03 pm, PerlFAQ Server wrote:
> This is an excerpt from the latest version perlfaq8.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is athttp://faq.perl.org.
>
> ------------------------------------------------------------ --------
>
> 8.42: How do I make a system() exit on control-C?
>
> You can't. You need to imitate the system() call (see perlipc for sample
> code) and then have a signal handler for the INT signal that passes the
> signal on to the subprocess. Or you can check for it:
>
> $rc = system($cmd);
> if ($rc & 127) { die "signal death" }
>
> ------------------------------------------------------------ --------
>
> The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
> are not necessarily experts in every domain where Perl might show up,
> so please include as much information as possible and relevant in any
> corrections. The perlfaq-workers also don't have access to every
> operating system or platform, so please include relevant details for
> corrections to examples that do not work on particular platforms.
> Working code is greatly appreciated.
>
> If you'd like to help maintain the perlfaq, see the details in
> perlfaq.pod.
>
> --
> Posted via a free Usenet account fromhttp://www.teranews.com
Instead of using system($cmd); use $answ = `$cmd` .....You can
Control-C out of that.
Re: FAQ 8.42 How do I make a system() exit on control-C?
am 29.08.2007 18:22:23 von brian d foy
In article <1188328268.556963.61700@57g2000hsv.googlegroups.com>, tk
wrote:
> On Aug 27, 3:03 pm, PerlFAQ Server wrote:
> > 8.42: How do I make a system() exit on control-C?
> Instead of using system($cmd); use $answ = `$cmd` .....You can
> Control-C out of that.
That's a different question :)
Backticks does a different job. IF you want your output to go to STDOUT
as it happens, you need system() (or a piped open).
Also, when you interrupt a Perl program using backticks, it kills the
whole program, not just the command you're running through the shell.
--
Posted via a free Usenet account from http://www.teranews.com