STDOUT and STDERR redirection fails for forked process

P

Peter

Hi,

I am trying to redirect STDERR to STDOUT and catching the returncode
using the script below.
Currently every error is redirected to the terminal instead of to
STDERR or STDOUT, so i am not able to catch the output if it
originates from a process's STDERR.

Any ideas/suggestions why STDERR is not redirectoed ? (i assume that
the RC is always 0 because of the failed STDERR redirection).

## Issue the command by forking the process and monitoring the
output
if (open STATUS, "$cmdstr 2>&1 |") {
while (<STATUS>) {
$result .= $_ ;
}
close STATUS ;
$rcverror = $? >> 8;
$errmsg = $! ;

}
else {
$errmsg = "Fork failed for \'$cmdstr\'" ;
$rcverror = -2 ;
}

# reset the alarm
alarm(0) ;
$rcvtimeout = 0 ;
} ;

Peter
 
B

Brian McCauley

Hi,

I am trying to redirect STDERR to STDOUT and catching the returncode
using the script below.
Currently every error is redirected to the terminal instead of to
STDERR or STDOUT, so i am not able to catch the output if it
originates from a process's STDERR.

Any ideas/suggestions why STDERR is not redirectoed ? (i assume that
the RC is always 0 because of the failed STDERR redirection).

## Issue the command by forking the process and monitoring the
output
if (open STATUS, "$cmdstr 2>&1 |") {
while (<STATUS>) {
$result .= $_ ;
}
close STATUS ;
$rcverror = $? >> 8;
$errmsg = $! ;

}
else {
$errmsg = "Fork failed for \'$cmdstr\'" ;
$rcverror = -2 ;
}

# reset the alarm
alarm(0) ;
$rcvtimeout = 0 ;
} ;

Peter

I can't see anything wrong with that code, but then again I can't run
it because it's incomplete and the problem could easily lie in the
bits you don't show us anyhow.

Please post a _minimal_ but _complete_ script that you've actually run
and found to produce the effect you are trying to understand.

This advice, and much more, can be found in the posting guidelines.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top