in reply to Re: How to store the output of the process in my own array?
in thread How to store the output of the process in my own array?

thank you very much. All the output can be store in the array but I still meet a small problem. I input ls command, and then print @mylog, but it doesn't contain the result of ls. When I input quit command to quit ftp, and then print @mylog, I get the ls result and quit result together. How can I solve this problem? Thanks a log. By the way, I use to meet this problem when I use C++ and C# to write the same program. In C++ and C#, anonymous pipe is used to implement it and I use multi-thread to solve the problem.
  • Comment on Re: Re: How to store the output of the process in my own array?

Replies are listed 'Best First'.
Re: Re: Re: How to store the output of the process in my own array?
by bart (Canon) on Mar 01, 2004 at 11:14 UTC
    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.

Re: Re: Re: How to store the output of the process in my own array?
by matija (Priest) on Mar 01, 2004 at 12:19 UTC
    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.

      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.