Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Use of IPC::Run rather than system()

by gmarler (Acolyte)
on Jul 16, 2003 at 15:43 UTC ( #274875=perlquestion: print w/ replies, xml ) Need Help??
gmarler has asked for the wisdom of the Perl Monks concerning the following question:

Given the following scenario:

A Perl script calls an external program. The external program may or may not require input from the user, and output from the external program must appear on the user's terminal as it is emitted.

Normally I would use system() to do this sort of thing, but I would now like to additionally capture the STDOUT and STDERR of the external program in separate scalars within the Perl script.

The module IPC::Run seems to fit this need perfectly, but I'm not sure about the syntax, whether to use ptys or just plain filehandles, etc. I didn't see anything that quite fits my requirements in the documentation for this module. Maybe I missed something...

Searching the newsgroups and this site have yielded nothing either. Any tips?

Comment on Use of IPC::Run rather than system()
Re: Use of IPC::Run rather than system()
by dragonchild (Archbishop) on Jul 16, 2003 at 15:53 UTC
    Test::Cmd seems to do it ... Check there. :-)

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Use of IPC::Run rather than system()
by Rex(Wrecks) (Curate) on Jul 16, 2003 at 16:33 UTC
    From the description of system in the Camel:

    "To capture output from a command, use backticks or qx// instead."

    Update: I seem to have misread the question, the way I read it would have been a simple split operation an any output. Being ESL, it didn't sink in that the poster wanted to split up STDERR and STDOUT. My mistake, thanks fot the spanking :)

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
      Except
      I would now like to additionally capture the STDOUT and STDERR of the external program in separate scalars within the Perl script.

      Makeshifts last the longest.

        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.

Re: Use of IPC::Run rather than system()
by zentara (Archbishop) on Jul 17, 2003 at 16:00 UTC
    I've used IPC to run commands and capture output. On occaision I needed to get input to the command I'm running. What I did was use a local STDIN:
    print "Insert blank cdrom ,press enter\n" { local *STDIN; open( STDIN, "< /dev/tty" ); my $ok = <STDIN>; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://274875]
Front-paged by Aristotle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2014-08-29 05:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls