Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Capturing STDOUT and STDERR of system command, with pure perl? (files)

by EvanK (Chaplain)
on Aug 24, 2007 at 17:59 UTC ( [id://634928]=note: print w/replies, xml ) Need Help??


in reply to Re: Capturing STDOUT and STDERR of system command, with pure perl? (files)
in thread Capturing STDOUT and STDERR of system command, with pure perl?

It's a wierd caveat, I know, but the command I'm executing could contain anything, including its own file descriptors.
# command that redirects STDERR to file $command = 'myapp --flag=somearg 2>>/var/log/myapp.err';
In such a case, if I just add new descriptors to the command, the original descriptor is apparently ignored, and the new one is used instead (on OSX anyway; YMMV).
# NOTHING is written to the original .err file # instead, STDERR is sent to STDOUT qx($command 2>&1)
So I needed a way to execute the command unaltered, then catch the output. I respect the constructive criticism though.

At any rate, xdg's suggestion works well, and I may end up taking your other advice and temporarily redirect the script's stdout/err to scalars just to avoid the girth of one more dependacy :)

__________
Systems development is like banging your head against a wall...
It's usually very painful, but if you're persistent, you'll get through it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://634928]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-25 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found