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

How to use perl to capture its output while inputting data to an external command

by wangliang (Initiate)
on Sep 24, 2021 at 02:02 UTC ( #11136975=perlquestion: print w/replies, xml ) Need Help??

wangliang has asked for the wisdom of the Perl Monks concerning the following question:

I need to use perl script to capture output from two programs when inputing some thing to them.

the first program called sac is used in shell like this:

$sac SAC> I input some thing and enter SAC> output some content that I need to capture SAC> I type 'quit' and enter $

the second program called gmt is used in shell like this:

$gmt parameters I input some thing and enter I input some thing and enter Ctrl+D output some content that I need to capture $
Thank you!

Replies are listed 'Best First'.
Re: How to use perl to capture its output while inputting data to an external command
by Fletch (Chancellor) on Sep 24, 2021 at 03:54 UTC

    Something like IPC::Run will (presuming the presence of an *NIX-y enough OS with ptys) make expect-ish automation of interactive programs possible. Alternately there's . . . erm, Expect. Use one of those to start your program, send it your input, read back the output, yadda yadda yadda.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: How to use perl to capture its output while inputting data to an external command
by hippo (Bishop) on Sep 24, 2021 at 08:24 UTC
Re: How to use perl to capture its output while inputting data to an external command
by karlgoethebier (Abbot) on Sep 24, 2021 at 18:41 UTC

    BTW and just for curiosity and for my mental health: Is this a homework some weird professor imagined? No kidding. And best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2021-10-17 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (71 votes). Check out past polls.

    Notices?