Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: Best Way to Redirect STDERR to a Scalarby shenme (Priest) |
on Sep 14, 2003 at 01:17 UTC ( [id://291327]=note: print w/replies, xml ) | Need Help?? |
Perhaps the way you were testing redirecting STDERR confused other responders. (Then again you may have confused me - see davido's response.) If you want to capture the STDERR output of another program that you start it gets differently complicated than just playing with the STDERR of your own program.
The various methods of TIE'ing STDERR won't work as they don't affect the STDERR filehandle (or more particularly the file descriptor ala fileno(STDERR)). And you can play with open's using '>&STDERR' but that's still playing only with the running program. On an *nix you could use fork and capturing output from child processes or any of the neat ways of doing the same using the open forms. But since you mention ActiveState we should probably try for less complicated ways of doing things. Would the code below work for you? Namely, can you execute the program using the backtick operator? The outputs returned from the tests (on my system) were: Executed command 'net use' >>> New connections will not be remembered. >>> >>> >>> Status Local Remote Network >>> >>> ------------------------------------------------------------------------------- >>> Disconnected Z: \\tls2ka\c$ Microsoft Windows Network >>> The command completed successfully. >>> Executed command 'net arf' Process returned error status '1' >>> The syntax of this command is: >>> >>> >>> NET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP | >>> HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION | >>> SHARE | START | STATISTICS | STOP | TIME | USE | USER | VIEW ] >>> Executed command 'netz arf' Process returned error status '1' >>> 'netz' is not recognized as an internal or external command, >>> operable program or batch file.I used the net command as it prints normal output to STDOUT (first test) but error output to STDERR (second test) as does the OS (third test).
In Section
Seekers of Perl Wisdom
|
|