IPC::PerlSSH uses IPC::Open2 to spawn an ssh process with pipes for input and output. When you kill the ssh server on the remote host this sub-process terminates. Then, when the second $ips->eval() runs it attempts to write to the pipe, which fails and generates a SIGPIPE signal to the parent process (your script). You don't have a handler for SIGPIPE and the default action is to terminate your process, but with Deferred Signals (Safe Signals) this signal is deferred until the read from STDIN completes. As soon as the read completes, your process is terminated, without continuing to test the error returned from the eval or printing "done".

Try adding a signal handler for SIGPIPE.

use strict; use warnings; use IPC::PerlSSH; eval { $SIG{PIPE} = sub { die "pipe dreams"; }; my $ips = IPC::PerlSSH->new( Host => "localhost" ); print $ips->eval("1")."\n"; <>; # allow me to cut ssh connection print $ips->eval("2")."\n"; }; if ($@) { print "error: $@"; } print "done\n";

In reply to Re: SSH disconnect and IPC::PerlSSH (or GRID::Machine) by ig
in thread SSH disconnect and IPC::PerlSSH (or GRID::Machine) by wiliv

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.