STDOUT and STDERR redirection fails for forked process
- From: Peter <mailbox@xxxxxxxxxxxxxx>
- Date: Thu, 19 Jul 2007 01:06:10 -0700
Hi,
Read the manpages, googled around, found some samples and followed
those to get it to work... but still fails..
What do i want? Simply, fork a command using the OPEN instruction,
redirect STDERR to STDOUT and capture the returncode of the executed
command.
I wrote the code wich is printed below, which works fine. Only output
from STDERR is not redirected to STDOUT but printed to the terminal
and the returncode is not captured. (So somehow redirected to STDOUT
but outside the open statement).
e.g. when the routine executes 'ls -Q' which sends the errormessage to
STDERR and a RC=2, the output from STDERR is printed to the terminal
and the returncode ($?) is 0.
Any ideas? suggestions?
Peter
Jul19 10:01:40 INF Data received from client "05794A6E5CD1122F ls -Q"
Jul19 10:01:40 DBG subroutine loccmd (15) (ls -Q)
Jul19 10:01:40 DBG Issuing command 'ls -Q'
ls: Not a recognized flag: Q
Usage: ls [-1ACFLNRabcdefgilmnopqrstuxE] [File...]
Jul19 10:01:40 DBG leaving subroutine loccmd passing values '0' '' ''
eval {
local $SIG{ALRM} = sub { die "Timed Out!\n" } ;
# set the alarm
alarm($timeout);
## Issue the command by forking the process and monitoring the
output
if (open STATUS, "$cmdstr 2>&1 |") {
while (<STATUS>) {
$result .= $_ ;
}
$errmsg = $! ;
$rcverror = $? ;
close STATUS ;
}
else {
$errmsg = "Fork failed for \'$cmdstr\'" ;
$rcverror = -2 ;
}
# reset the alarm
alarm(0) ;
$rcvtimeout = 0 ;
} ;
.
- Follow-Ups:
- Re: STDOUT and STDERR redirection fails for forked process
- From: anno4000
- Re: STDOUT and STDERR redirection fails for forked process
- Prev by Date: Re: new lines in the way
- Next by Date: Re: new lines in the way
- Previous by thread: FAQ 4.45 How do I find the first array element for which a condition is true?
- Next by thread: Re: STDOUT and STDERR redirection fails for forked process
- Index(es):
Relevant Pages
|
|