@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.

In reply to Re^2: How can I show all input and output with Expect.pm by GeorgeAdams
in thread How can I show all input and output with Expect.pm by GeorgeAdams

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.