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

Philip J. Hollenback philiph at pobox.com
Fri Jul 1 22:58:18 PDT 2011


On Fri, 24 Jun 2011 14:52 -0700, "yary" <not.com at gmail.com> wrote:
> Looking at the docs from IO::CaptureOutput, it will only return after
> the code is done, so you can't use it exactly in that case, as you
> suspected.
> 
> You have two options:
> 
> 1. Always pipe the password to the external program's stdin. If it
> needs it, it will get it, if it doesn't need it, no harm done. That
> assumes that the external program reads nothing else from its stdin.
> (Some programs read password from the terminal and not stdin, which is
> could complicate this approach).
> 
> 2. Use IPC::Open2 or IPC::Open3. Check for a password at the start of
> reading, handle it, continue.

Thanks for you advice!  I ended up dealing with this in a slightly
different way.  I realized the external program had a 'ping' command
line option, which just does the password authentication and checks if
the server it depends on is alive.

Since this remote application caches authentication for several hours,
that's all I needed.  I just do a regular system("application ping")
which allows the person running my script to answer the password prompt
if it comes up.  Then since the authentication is cached, I can use
IO::CaptureOutput for all subsequent calls to the external app and not
have to worry about re-authenticating.

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



More information about the SanFrancisco-pm mailing list