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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |