|
From: Jamie C. <jca...@we...> - 2009-10-21 07:21:03
|
On 20/Oct/2009 21:34 David Drayton <ddr...@pu...> wrote ..
> Hey guys,
>
> I have to run a command that:
> a) displays progressive output as it runs, and
> b) continues to run, even if the user moves to another page
>
> I have tried the code below, which satisfies (a) but I noticed that when I went
> to another page, it would stop running and so doesn't satisfy (b) as well. Note
> that I am only using ping as a test.
>
> open(CMD, "ping 127.0.0.1 2>&1 |");
> while(<CMD>) {
> print $_;
> }
> close(CMD);
The reason it gets terminated when the user leaves the page is that
the command receives a SIGPIPE signal, which by default kills it.
The way to prevent this is to add the following line at the top of
your Perl script :
$SIG{'PIPE'} = 'IGNORE';
- Jamie
|