From: Robin L. P. <rlp...@di...> - 2010-09-23 17:52:56
|
On Thu, Sep 23, 2010 at 01:14:04PM +0530, saravana kumar wrote: > Resending it again.... > > --Saravana > > ---------- Forwarded message ---------- > From: saravana kumar <sar...@gm...> > Date: Wed, Sep 22, 2010 at 5:43 PM > Subject: Get the output from expect > To: exp...@li... > > > Hello All, > > I want to get the output from expect. > I tried with $exp->before(), $exp->after() and $exp->match(), but nothing > worked for me. > > Please find the script below: > > use strict; > use warnings; > use Expect; > my $output; > my $timeout = 200; > my $command = 'telnet pvham3-c.ind.hp.com'; > my $user='Admin'; > #my $host='192.168.47.11'; > my $password = 'Admin'; > my $exp = Expect->spawn($command) > or die "Cannot spawn $command: $!\n"; > $exp->expect($timeout, [ qr{MP login: } , sub {$exp->send("$user\n")} ]); > $exp->expect($timeout, [ qr{MP password: }, sub {$exp->send("$password\n")} > ]); > $exp->expect($timeout, [ qr{MP> }, sub {$exp->send("CO\r"); > $exp->send("\cEcf"); $exp->send("\r"); $exp->send("map -r\r")} ]); > $exp->expect($timeout, [ qr{fs*}, sub {$exp->send("cls\r"); $exp->send("map > -r\r")} ]); > #$exp->expect($timeout, [ qr{\$ } , sub {$exp->send("ls\n")} ]); > #$exp->expect($timeout, [ qr{fs*} , sub {print "got the output: '". > $exp->before(). $exp->after(). $exp->match() . "'\n"} ]); > $output=$exp->before() . $exp->after(). $exp->match(); > $exp->soft_close(); > print "The output is ********* $output\n"; > > >From the above script, i would want to capture the output from > "$exp->send("map -r\r")". >From "man expect 3pm": I just want to read the output of a process without expect()ing anything. How can I do this? [ Are you sure you need Expect for this? How about qx() or open("prog|")? ] By using expect without any patterns to match. $process->expect(undef); # Forever until EOF $process->expect($timeout); # For a few seconds $process->expect(0); # Is there anything ready on the handle now? Ok, so now how do I get what was read on the handle? $read = $process->before(); -Robin -- http://singinst.org/ : Our last, best hope for a fantastic future. Lojban (http://www.lojban.org/): The language in which "this parrot is dead" is "ti poi spitaki cu morsi", but "this sentence is false" is "na nei". My personal page: http://www.digitalkingdom.org/rlp/ |