[sf-perl] capture stdout and stderr, possibly supply input

Philip J. Hollenback philiph at pobox.com
Thu Jun 23 17:40:10 PDT 2011


I am writing a perl script that needs to invoke an external program and
collect the stdout and stderr of that program.  I also need to check the
return code.

That's all pretty simple to do in a few ways, for example I tried
IO::CaptureOutput and it works fine.

My complication is that this external program may stop and ask for a
password.  If that happens, I need to get a password from the user and
feed it to the external program to continue.  Then I can capture the
output I need after that (the password prompt will always happen before
all other output).  Thus I can't really use IO::CaptureOutput because it
will halt and wait for the password input without displaying anything on
stdout (since I'm already capturing stdout).

I assume I can do this all with Expect.pm, but I wonder if anyone can
think of a simpler way to deal with this one special input case.

Or alternately, am I just missing something obvious?

Thanks,
P.
--  
Philip J. Hollenback
philiph at pobox.com
www.hollenback.net



More information about the SanFrancisco-pm mailing list