[comp.lang.perl] how to read stdout AND stderr from a program

al@ee.pitt.edu (Alan Martello) (03/02/90)

Related to my previous posting concerning dumps, I want
to do open(FH, "program |&")  --- but this doesn't work.
Is there an easy way to accomplish the same thing?
(I tried "program |& cat |") but to no avail....
*******************************************************************
       Alan R. Martello        Electrical Engineering Dept.
        al@ee.pitt.edu           University of Pittsburgh
*******************************************************************

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (03/02/90)

In article <7001@pitt.UUCP> al@ee.pitt.edu (Alan Martello) writes:
: Related to my previous posting concerning dumps, I want
: to do open(FH, "program |&")  --- but this doesn't work.
: Is there an easy way to accomplish the same thing?
: (I tried "program |& cat |") but to no avail....

That's csh syntax, and perl mostly only invokes sh (except for globbing).  Say

	open(FH, "program 2>&1 |")

That says fd 2 is a duplicate of fd 1.

Larry

merlyn@iwarp.intel.com (Randal Schwartz) (03/02/90)

In article <7001@pitt.UUCP>, al@ee (Alan Martello) writes:
| Related to my previous posting concerning dumps, I want
| to do open(FH, "program |&")  --- but this doesn't work.
| Is there an easy way to accomplish the same thing?
| (I tried "program |& cat |") but to no avail....

That's cuz system() and friends follow the syntax of the One True
Shell, the Bourne shell.  (Csh is a
hack-turned-least-common-denominator, sorta like VHS tape and
processors that end in 86, but that's another story...)  All Unix
hackers should learn the syntax of /bin/sh and /bin/ed, to see where
all these nifties actually started.

Enough motherhood and apple pie.  The answer to your question is:
	open(FH,"program 2>&1|")

print "Just another Perl hacker," if "there's nothing better to do";
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/