victor@irt.watson.ibm.com (Victor Miller) (02/22/91)
Suppose that foo is a system command, which produces output on STDOUT, and might produce output on STDERR. How can I capture both in perl variables (short of redirecting STDERR to a file - ugh!)? -- Victor S. Miller Vnet and Bitnet: VICTOR at WATSON Internet: victor@ibm.com IBM, TJ Watson Research Center
rbj@uunet.UU.NET (Root Boy Jim) (02/22/91)
In article <VICTOR.91Feb21160105@irt.watson.ibm.com> victor@ibm.com writes: >Suppose that foo is a system command, which produces output on STDOUT, >and might produce output on STDERR. How can I capture both in perl >variables (short of redirecting STDERR to a file - ugh!)? Two ways: First, you ask nicely: "Larry, I know I can say: $out = `cmd args`; but I want stderr too, so how about if I say: ($out,$err) = `cmd args`; what do you think?" To which Larry will probably respond: "I'm too busy hacking in even parity generation of BCD trigraphs for RBJ, so take a hike." More likely, you open two pipes, fork, do the standard plumbing, exec the command in the child, have the parent select on the two pipes until you've sucked them dry, wait on the child, then close the parent's pipes. Hmmmm, that temporary file looks pretty good now don't it? -- [rbj@uunet 1] stty sane unknown mode: sane
tchrist@convex.COM (Tom Christiansen) (02/22/91)
From the keyboard of rbj@uunet.UU.NET (Root Boy Jim): :Two ways: First, you ask nicely: "Larry, I know I can say: :$out = `cmd args`; but I want stderr too, so how about if I say: :($out,$err) = `cmd args`; what do you think?" Nope -- breaks code. That reads the first line into $out, the second into $err. :To which Larry will probably respond: "I'm too busy hacking in :even parity generation of BCD trigraphs for RBJ, so take a hike." death to trigraphs. :More likely, you open two pipes, fork, do the standard plumbing, exec :the command in the child, have the parent select on the two pipes until :you've sucked them dry, wait on the child, then close the parent's pipes. : :Hmmmm, that temporary file looks pretty good now don't it? Quite. Or just 2>&1 and don't worry about it. --tom -- "UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things." -- Doug Gwyn Tom Christiansen tchrist@convex.com convex!tchrist