I have to capture output of the send command when using Perl Expect
module.
I know that in shell or Tcl I can use puts $expect_out(buffer);
to capture the previously run command.
How can I do the same thing in Perl?
I am sending below command on remote machine:
$expect->send("stats\n");
I need to capture the stats
output in some variable.
First of all you have to know how the last line of your CLI looks like after the output of your requested data. The
Expect
cann search for a certain Pattern within your defined timeout. If it found sth. you can capture everything since your$expect->send($command)
with the$exp-before()
-command. Or if you wish to capture everything after your command just use$expect->after()
without checking for a special symbol.Let me give you an example:
So you have to fire your command, then expect your command been fired. After this you can fetch everything till your command prompt, in my case it's indicated by the
#
. The rows between your command and the last$expect->expect($timeout,["#"]
will be stored in $data as a single string. After that you can process this String.I hope I could help you a bit further. ;)