i have capture output of send command when using perl expect
module.
i know in shell or tcl can use puts $expect_out(buffer);
capture run command.
how can same thing in perl?
i sending below command on remote machine:
$expect->send("stats\n");
i need capture stats
output in variable.
first of have know how last line of cli looks after output of requested data. expect
cann search pattern within defined timeout. if found sth. can capture since $expect->send($command)
$exp-before()
-command. or if wish capture after command use $expect->after()
without checking special symbol.
let me give example:
$expect->send("$command\n"); #mask pipe-symbol later use. expect expects valid regex $command =~ s/\|/\\\|/; #if huge amount of data requested have avoid timeout $expect->restart_timeout_upon_receive(1); if(!$expect->expect($timeout, [$command])){ #timeout die: "timeout @ $command"; }else{ #command found, no timeout $expect->after(); $expect->restart_timeout_upon_receive(1); if(!expect->expect($timeout,["#"])){ die "timeout @ $command"; } else{ $data = $expect->before(); #fetch before last expect() call } } return $data;
so have fire command, expect command been fired. after can fetch till command prompt, in case it's indicated #
. rows between command , last $expect->expect($timeout,["#"]
stored in $data single string. after can process string.
i hope bit further. ;)