The perl script itself is the wrapper to the program. I have gotten to this stage now
#!/usr/bin/perl -w
use POSIX qw(:signal_h :errno_h :sys_wait_h);
$command = $ARGV[0];
parse();
if (!defined ($pid = fork()))
{
die "cannot fork: $!";
}
elsif ($pid == 0)
{
exec("$command");
}
else
{
waitpid($pid, 0);
if (WIFEXITED($?))
{
print "Exited\n";
}
elsif (WIFSIGNALED($?))
{
$sig = WTERMSIG($?);
if ($sig == 11)
{
print "Segfault\n";
exit 11;
}
print "Signaled $sig\n";
}
else
{
print "EH\n";
}
}
close STDOUT;
exit 0;
sub parse
{
my $pid;
return if $pid = open(STDOUT, "|- ");
die "cannot fork: $!" unless defined $pid;
while (my $line = <STDIN>)
{
print "$line";
}
exit;
}
So I am able to capture the program and take note of when it segfaults, and also parse the programs standard out. All I am missing now is capturing the programs stderr...
Apart from using IO::Capture is there another way that will simply add to the above code, or is this just wishful thinking?
Thank you very much to everyone who have replied to my question.
|