Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!wuarchive!rice!uw-beaver!zephyr.ens.tek.com!tektronix!reed!intelhf!ichips!inews!rpaul From: rpaul@hopi.intel.COM (Richard Paul~) Newsgroups: comp.lang.perl Subject: How can I capture STDERR from a command executed externally Message-ID: <4352@inews.intel.com> Date: 22 May 91 14:57:31 GMT Sender: news@inews.intel.com Reply-To: rpaul@sedona.intel.com Distribution: usa Organization: Intel Corporation, ASIC in the Desert Lines: 42 I want to be able to capture STDERR from an external command and do some substitution and reprint it back out. Following is an experiment I was doing to get this to work. The ls command used is the GNU ls, which with the -h option, prints its options to stderr: #!/stor/gnu/bin/perl open(STDERR, ">&STDOUT"); open(STDOUT); select(STDERR); $| = 1; # make unbuffered open(TMP, "ls -h >&STDERR"); while() { s/\+/\%/g; print $_; } close(TMP); close(STDERR); close(STDOUT); The stderr is still going to the tty and not the STDERR filehandle. Is there a way to capture the STDERR output of the TMP filehandle. Any help would be greatly appreciated. I am using the following perl: $RCSfile: perl.c,v $$Revision: 4.0.1.1 $$Date: 91/04/11 17:49:05 $ Patch level: 3 Thanx -- -- ___________________________________________________________________________ | Name: Richard Paul | US-Mail: 5000 W. Chandler Blvd. | | Dept: AME Methodology, SQA | M-stop: CH3-36 | | Group: Arizona Microcomputer Eng. | Chandler AZ, 85226 | | Tel: 602 554 2793, Fax: 602 554 7281 | E-mail: rpaul@sedona.intel.com | | UUCP: decwrl!apple!oliveb!orc!inews!rpaul@sedona.intel.com | | Org: Intel Corporation, ASIC in the Desert, | ---------------------------------------------------------------------------