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

Re: Re: Use of IPC::Run rather than system()

by IlyaM (Parson)
on Jul 16, 2003 at 16:50 UTC ( #274927=note: print w/ replies, xml ) Need Help??


in reply to Re: Use of IPC::Run rather than system()
in thread Use of IPC::Run rather than system()

It doesn't help if you want to capture STDERR and STDOUT in separate scalars.

To answer gmarler's question: if you just want to capture STDERR and STDOUT for an external program then it is rather easy to do with IPC::Run:

use IPC::Run qw(run); my($out, $err); run ['/path/to/prog', 'arg1', 'arg2'], '>', \$out, '2>', \$err;

You can find more complex examples in following nodes:

--
Ilya Martynov, ilya@iponweb.net
CTO IPonWEB (UK) Ltd
Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
Personal website - http://martynov.org


Comment on Re: Re: Use of IPC::Run rather than system()
Download Code
Re: Re: Re: Use of IPC::Run rather than system()
by gmarler (Acolyte) on Jul 16, 2003 at 18:01 UTC

    Thanks for that - note however that in addition to capturing STDOUT/STDERR, I still need to have the STDIN/STDOUT/STDERR of the external program connected to the terminal where the person is running the script, in case the external program requires input from the user, and so that any output is immediately visible to the user, in addition to being saved in the scalar(s).

    I'll try your recommendation out though - maybe it does give me what I want.

      For STDIN/-ERR, just print the output to the appropriate handles yourself. For STDIN, if you have taken control of the subprocesses STDIN yourself, just copy the user input in there yourself. You can do that "realtime" rather than post mortem by passing closures rather scalar refs, if memory serves.

      Makeshifts last the longest.

        Something like this should work:
        use IPC::Run qw(run); my ($out, $err) = ('', ''); run(['/path/to/prog', @args], '>', sub { $out .= $_[0]; print $_[0] }, '2>', sub { $err .= $_[0]; print $_[0] });

        --
        Ilya Martynov, ilya@iponweb.net
        CTO IPonWEB (UK) Ltd
        Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
        Personal website - http://martynov.org

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2014-04-20 14:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls