Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: thread save calling an external command

by Anonymous Monk
on Jul 06, 2016 at 13:00 UTC ( #1167296=note: print w/replies, xml ) Need Help??


in reply to Re: thread save calling an external command
in thread thread save calling an external command

Simple... and neat using File::Temp:

use File::Temp; sub cmdrun { my $cmd = shift; my $out = File::Temp->new(); my $err = File::Temp->new(); local $/; `$cmd >$out 2>$err`; $?>>8, scalar <$out>, scalar <$err> } use Data::Dumper; print Dumper cmdrun( q(perl -le "warn q(NOISE); print q(OUTPUT); exit +42;") );

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2022-05-16 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (62 votes). Check out past polls.

    Notices?