in reply to Re: How can I show all input and output with Expect.pm
in thread How can I show all input and output with Expect.pm

@frozenwithjoy, thanks for the reply. To answer your questions:

  1. It doesn't seem that reversing the order of the commands
    print "$command\n";
    $exp->send("$command\n");
    
    makes any difference either to the STDOUT or logfile output. It still gives:
    (1) (2) Here is the second command
    error
    (3) Error on command #3
    (4) commit
    This is the last command
    Committing data
    (5) (6) exit
    Exiting program...
    
  2. The server script has to print out the "(1) " before it receives any input. When it gets a line, it simply prints out "(2) " , waits for the next line, prints "(3) ", waits for the next line, etc. The code isn't optimized, but that's at least the explanation of why the $counter = 1 and the first print statement comes before the loop.

    That is, if you ran the server script and entered stuff, you'd get:

    (1) This is the first line I typed.  Now I'm hitting <ENTER>
    (2) I'm typing more stuff.
    (3) exit
    Exiting program...
    
  3. Good question. The server script is actually representing what I cannot control in this. It may be a company-wide program I'm trying to interact with, or a Juniper router, or an IDS box, or probably a lot of other things. So unfortunately for this example I have to pretend that I can't modify the server's output. All I can do is interact with the (program, router, server, etc.) myself, see what it outputs when I interact with it manually, then try to reconstruct that exact output when my Expect.pm script interacts with the (program, router, server, etc.) in the same way.
  • Comment on Re^2: How can I show all input and output with Expect.pm