Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: STDERR and STDOUT redirection from codeopen/code

by tachyon (Chancellor)
on Apr 11, 2002 at 20:13 UTC ( #158419=note: print w/replies, xml ) Need Help??


in reply to STDERR and STDOUT redirection from codeopen/code

This will do the trick for you (on *nix):

my $command = 'ls -al'; open CMD, "$command 2>&1|" or die $!; my @output = <CMD>; close CMD;

The open executes $command. The 2>&1 redirects STDERR to STDOUT and backgrounds process. The | pipes the output to the CMD filehandle which we then read from as usual.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: STDERR and STDOUT redirection from codeopen/code
by dpatrick (Scribe) on Apr 11, 2002 at 20:24 UTC
    Thanks. That's exactly what I was looking for. This is what we had in the cron job but I wasn't sure whether I could do the same from Perl.

    dpatrick
    - I think scsh is cool.
    Open Sourceror, Perlmonk
    http://perlmonk.org/~dpatrick

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2023-06-07 23:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (29 votes). Check out past polls.

    Notices?