splitting stderr/stdout without using file



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);
}

.



Relevant Pages

  • Re: Capturing error msgs from output = `cmd`
    ... But could not capture the error. ... content of stdin, stdout and stderr just to inspect their contents, this is ... If, however, the command executed generates an error msg, the ...
    (comp.lang.ruby)
  • Re: zsh: STDERR to a variable?
    ... one wanted to capture both stderr *and* stdout. ... I meant capturing both stderr and stdout ... In my address everything before the first period is backwards; ...
    (comp.unix.shell)
  • Getting stderr when using -|
    ... and stderr from this system command. ... If I only wanted stdout, ... But how does one capture stderr as well? ...
    (comp.lang.perl.misc)
  • RE: Capturing stdout and stderr without redirection
    ... Separate callback subs for STDOUT and STDERR... ... When all done, if array size> 0, fire off an email ... that, but is there a better, more elegant way to capture any ...
    (perl.beginners)
  • Re: Exceptions in embedded env.
    ... I notice that j.l.Exception does not have a LineNumber field. ... > There is no stdout or stderr that I have access to. ... > an output stream that I could capture... ...
    (comp.lang.java.programmer)