Re: how to get the output from: Win32::Process::Create



Paul Lalli wrote:
You apparently have two requirements. One is that you need to capture
the output of the program. The other is that you need to get the pid
of the program so you can later kill it. These two requirements seem,
to me, to be contraditory.

I guess the other possibility is to fork your program, and set up the
child to have a signal handler to be notified when the parent wants to
kill it....

[untested]

my $pid = fork();
if ($pid == 0) { #child

$SIG{INT} = sub { print "Parent told me to die!\n"; exit };

open my $pipe, "test.exe |" or die "Cannot open pipe: $!";
while (my $line = <$pipe>) {
process_line($line);
}
print "test.exe ended before parent told me to die!\n";
}
else { #parent
#do stuff
# la la la
if (want_to_kill()) {
kill ('INT', $pid);
}
#do more stuff, la la la
}

Paul Lalli

.



Relevant Pages

  • Re: Killing a process that takes too long
    ... and it does not guarantee that the child ... You can test it by placing $$ (process pid) in the output of these two ... So we need a way to kill several processes of the process group of the parent, ...
    (perl.beginners)
  • Re: killing off a process tree
    ... I would like this to be portable on both linux and windows. ... you can only use 0-9 on windows, and none of them seems to kill a tree. ... The thing is I only have the pid of the parent, ...
    (comp.lang.ruby)
  • Re: killing off a process tree
    ... I kill the parent, ... ' where N is the PID of your ... program you're calling does setsidor setpgrp() on its own, ...
    (comp.lang.ruby)
  • Re: how to kill children processes
    ... In the parent process, how do I kill all its children processes? ... but they could periodically check the pid ... If you want notification, ...
    (comp.unix.bsd.freebsd.misc)
  • Re: Periodic Fedora 9 system hangs with jumpy mouse
    ... kill -TERM pid ... to do with graphics card and driver. ...
    (Fedora)