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 (Bishop) 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 (Archbishop) 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»