It's somewhat gratifying to know that after all the time I spent looking through documentation and the code for Expect and Expect::Simple that there isn't actually a solution -- the alternative being that I spent all that time and still missed something obvious!

The fugly hack I outlined in the orig. post has been implemented and it's working fine.

If I were working on Expect::Simple myself (which I don't have time to do!), I might just wrap that particular hack/solution up in a new method named final_send() or send_and_end() or some such. It would have the same behavior as send(), but instead of looking for a prompt it actually would expect to get a type 3 error with zero exit status, and would throw exceptions if it doesn't find that state. So you would not get that "couldn't find a prompt" error, but instead something like "controlled program didn't end as expected.". You could include information in the error text as to whether it found one of the expected prompts instead or another kind of error was raised by Expect. The advantage of this approach is that the controller also controls when the script is expected to end; if the controlled program ends 'normally' at a point you didn't expect, that still causes an exception to be raised.

You might also want to modify the DESTROY block so that it doesn't try to end the program if it's already terminated itself.

NB: Edited for clarity.

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."


In reply to Re^2: How to handle Expect::Simple sessions to programs that end normally. by DrWhy
in thread How to handle Expect::Simple sessions to programs that end normally. by DrWhy

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.