I am troublesdhooting a perl expect script that interacts with a remote server running a custom OS on top of an OpenBSD kernel. The script creates an ssh connection and logs in successfully. It even shows the welcoming text of the custom OS and matches on the first custom OS's prompt. The script then sends a command to the remote server and the perl expect script echos back the command and closes the connection. I found the bit of trouble code in the Expect.pm module on or around lin 821 my $nread = sysread($exp, $buffer, 2048);. This sysread call fails to read anything off the socket after the system command is sent to the remote server and then sets $nread to 0 which is later interpreted into an EOF and sent to the server, $nread = 0 unless defined ($nread);.
if ($nread == 0) { ... ... blah blah $exp->hard_close(); }
First I thought it may be an issue with the tty or pty type because the app I am interacting with is not a standard type terminal service (popular Linux/BSD OS, cisco router, ssh console, etc). I tried setting the session to raw but that didn't help either. I then found some code in Expect.pm that appears to be re-assigning STDIN, STDOUT and STDERR starting on or around line 158:
close(STDIN); open(STDIN,"<&". $slv->fileno()) or die "Couldn't reopen STDIN for reading, $!\n"; close(STDOUT); open(STDOUT,">&". $slv->fileno()) or die "Couldn't reopen STDOUT for writing, $!\n"; close(STDERR); open(STDERR,">&". $slv->fileno()) or die "Couldn't reopen STDERR for writing, $!\n";
Could this have anything to do with it? Anyone suggestions on how I can get this to work with my non-standard OS?

In reply to Expect.pm early termination? by Elijah

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.