Results 1 to 3 of 3
Hi,
I'm new to both Perl and "Expect" and recently to automate some prosaic
tasks i tried writing a small script(see the snippet below) which tries to
log onto a ...
- 08-25-2009 #1
How to grab stdout when using Expect
Hi,
I'm new to both Perl and "Expect" and recently to automate some prosaic
tasks i tried writing a small script(see the snippet below) which tries to
log onto a remote machine with a user credentials and issues some commands.
I need to grab the output of the command executed, how should i go about
doing that ?
<sample code>
#!/usr/bin/perl
use Expect;
my ($host,$testUser,$userPasswd) = ('venus','foo','foo123');
my $timeout = 15;
$cmd = "cat /etc/passwd";
my $exp1=Expect->spawn("ssh $testUser\@$host $cmd");
$exp1->expect($timeout,["password:" => sub {my $self = shift;
$self->send("$userPasswd\n")}]);
$exp1->expect($timeout,["\$ " => sub {my $self = shift;
$self->send("$userPasswd\n")}]);
my $rc = `echo $?`;
print "$rc\n";
<sample code>
Thanks,
Amit
- 08-25-2009 #2
- 08-25-2009 #3
The above change will only put the stderror in a file name
tmp.logile, In a similar fashion, stdout(whose descriptor number is "1" can be made to logged in a file)


Reply With Quote
