in reply to Re^2: Perl non-blocking IPC
in thread Perl non-blocking IPC

I don't now how to get the pid of the tail process. Any suggestions?

$fh = FileHandle->new("tail -f -n 25 command_file |");

The only way to get the $pid is to use a piped-open as described in perldoc perlipc, or use something like IPC::Open3, but you sometimes get a shell pid, which then executes your program.

So use something like this:

my $fh = new FileHandle; my $pid = open( $fh , "tail -f -n 25 command_file | ") or die ; #..... # now you can check the output of ps to see if you get a shell $pid # or just your process $pid # then to make sure you kill all shells and commands, if you see # the $pid is the shell use Proc::Killfam; $mw->protocol('WM_DELETE_WINDOW' => sub { killfam 9,$pid; exit; }); # or put the killfam in the callback of an Exit button, etc
Before I get slapped on the wrist for using killfam 9, remember that 9 is an instant kill, you may want to use a softer signal like 15, to allow the program to gracefully close.

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^4: Perl non-blocking IPC
by brian42miller (Sexton) on Jul 07, 2011 at 16:26 UTC
    Thanks to all,

    That works great. I feel kind of guilty, I always seem to be asking for help and never giving (not that I have the expertise) help.

    Thanks again

    Brian