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

Hi all wise,
I am a perl newbie and this is my first post.
My problem:
I want to run a terminal program from within a perl script and parse its output.
Once invoked, the program stops and promts the user for a password, after which it continues to produce output on the screen.
I have been able to use the Expect module to enter the password. But I have no idea how to collect the output.
As of now:
my $cmd = Expect->spawn("program $params") or die "Couldn't run program"; unless($cmd->expect(2, "Password")) { print $cmd "passwd\n"; } #Here I would like to gather the output for parsing.
I tried something like:
$cmd->expect($timeot); $output = $cmd->before();
but $output comes out empty.
This must be a common problem but I have not been able to find one simple solution. Maybe Im low on google skills:)
Regards
Im on linux btw

Replies are listed 'Best First'.
Re: Automate program interaction
by lin0 (Curate) on Mar 09, 2007 at 22:54 UTC
Re: Automate program interaction
by TOD (Friar) on Mar 10, 2007 at 11:32 UTC
    maybe you should take a look at
    perldoc perlopentut
    the paragraphs on pipe opens might contain some of the answers you're looking for.