Hi,
I want to capture UNBUFFERED output from a C programme and then
control it depending on its output. Problem is nothing seems to
unbufferd the output from the C programme. Only when the child has
finished executing do I get all the output which is too late.
The C programe is just like hello world in a loop of 20.
Here is the code:
#!/usr/bin/perl -w
use IO::Handle;
sub killGroup {
# kill process group except self
local $SIG{HUP} = 'IGNORE';
kill (HUP, -$$);
print "killed child exit status $?\n";
}
if ($pid = open(READER, "-|")) {
# parent process
print "parent: starting\n";
while (<READER>) {
print "parent: $_";
killGroup if /3/;
}
close (READER);
} else {
# child process
die "cannot fork: $!" unless defined $pid;
$SIG{HUP} = sub {die "child: killed by parent\n"};
# try and un buffer output
STDOUT->autoflush(1);
print STDOUT "child: starting\n";
# start the C programme which has printf in a loop
exec("/home/robert/try8 2>&1");
exit 0;
}
I have tried all the recipes int the Perl cook book but none work.
Thanks,
Rob Key
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/