B
billy
I need to capture stdout and stderr but without using files for the
capture. This script will be part of a logging function that is called
from make. Make is processing as many jobs as the system loading can
handle. This script may be called 100k+ times and hundreds of times
simultanously, so writing to files is out of the question. I already
have a version in sh but it has to create several processes to
accomplich it's task. I am out to gain all the spedd I ppssibly can
..1 seconds is a lot of time saved over 100k calls.
I currently have a function System that I have used to capture both
stdout and stderr.
I need to modify this;
Here's what I have.
test code x.pl :
#!/usr/local/bin/perl
print STDOUT "$0 stdout\n";
print STDERR "$0 stderr\n";
exit 0;
main code :
#!/usr/local/bin/perl -w
use strict;
use warnings;
my ($stat,$ret) = System("x.pl");
print "ret = '$ret'\n";
sub System
{
my( $command ) = @_;
my $stat = undef;
my $ret = undef;
if (open PIPE , "$command 2>&1 |") {
while (<PIPE>) { $ret .= $_; }
close PIPE;
}
else {
Unknown("Failed to open pipe for '$command'!\n",1,1);
}
$stat = $? >> 8;
return ($stat,$ret);
}
capture. This script will be part of a logging function that is called
from make. Make is processing as many jobs as the system loading can
handle. This script may be called 100k+ times and hundreds of times
simultanously, so writing to files is out of the question. I already
have a version in sh but it has to create several processes to
accomplich it's task. I am out to gain all the spedd I ppssibly can
..1 seconds is a lot of time saved over 100k calls.
I currently have a function System that I have used to capture both
stdout and stderr.
I need to modify this;
Here's what I have.
test code x.pl :
#!/usr/local/bin/perl
print STDOUT "$0 stdout\n";
print STDERR "$0 stderr\n";
exit 0;
main code :
#!/usr/local/bin/perl -w
use strict;
use warnings;
my ($stat,$ret) = System("x.pl");
print "ret = '$ret'\n";
sub System
{
my( $command ) = @_;
my $stat = undef;
my $ret = undef;
if (open PIPE , "$command 2>&1 |") {
while (<PIPE>) { $ret .= $_; }
close PIPE;
}
else {
Unknown("Failed to open pipe for '$command'!\n",1,1);
}
$stat = $? >> 8;
return ($stat,$ret);
}