Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!gatech!ncar!elroy.jpl.nasa.gov!sdd.hp.com!uakari.primate.wisc.edu!aplcen!boingo.med.jhu.edu!haven.umd.edu!mimsy!mojo!eng.umd.edu!ziegast From: ziegast@eng.umd.edu (Eric W. Ziegast) Newsgroups: comp.lang.perl Subject: Re: How can I capture STDERR from a command executed externally Message-ID: <1991May23.204119.23595@eng.umd.edu> Date: 23 May 91 20:41:19 GMT References: <4352@inews.intel.com> <1991May23.055849.6100@jpl-devvax.jpl.nasa.gov> Sender: news@eng.umd.edu (C-News) Reply-To: ziegast@eng.umd.edu (Eric W. Ziegast) Distribution: usa Organization: College of Engineering, Maryversity of Uniland, College Park Lines: 35 (Larry Wall) writes: > You're making this all much too hard. Just say > > open(TMP, "ls -h 2>&1 |"); > while () { > tr/+/%/; > print; > } The above method will merge STDERR into STDOUT. In his book, Larry also shows another way of doing this where STDERR and STDOUT are still handled seperately. # Before your command: redirects STDERR open(SAVEERR, ">&STDERR"); open(STDERR, "> stderr_output_filename"); # Commands you would have used normally # Ex: open(TMP, "ls -h"); #After your command: restores STDERR close STDERR; open(STDERR, ">&SAVEERR"); After this, you can open the file "stderr_output_filename" and read what was sent to STDERR. If you just want to get rid of STDERR, use /dev/null for a filename. The same process would work with STDOUT with a few minor file handle changes. s/ERR/OUT/g +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+ | Eric W. Ziegast Internet: ziegast@eng.umd.edu | | Univ. of Merryland Phonenet: Eric@[301.405.3689] | +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+