I still meet a small problem. I input ls command, and then print @mylog, but it doesn't contain the result of ls.
The reason for the difference, is because ls detects whether it's connected to a pipe or to a TTY, and behaves differently for both cases. You have to fool it into believing it's connected to a terminal. The common way to do that, is to connect it to a pseudo-terminal.
To this end, you can use the module IO::Pty. And judging by the documentation, Expect (which I've never ever used in my life, sorry) ought to have support for it built-in.
Happy hunting.
| [reply] |
Well, from my experimenting with Expect it looks like the subroutine for logging the output is called when $object->expect is called, or even when $object->expect finds
a match. Probably also when it's buffer becomes full, but you realy don't want to count on that.
My suggestion is to put in some $object->expect calls that match on whatever prompt you are getting in your input stream.
| [reply] |
Thank you very much. Another veteran tells me another method. It looks like follow code:
my @array;
...
@array=$session->expect(...);
...
I put print @array after each call on the expect, and it works. It is strange because as far as I know, if under list context, the return value of the expect is not the content that output of the command line.
| [reply] |