in reply to Re^3: Problem with Net::SSH::Expect on unavailable hosts
in thread Problem with Net::SSH::Expect on unavailable hosts

It leads me to believe that, if by returning a failure state run_ssh() allows you to assume that the subprocess could not start, that it blocks its return until it has started otherwise.

The docs for run_ssh() further state " boolean: 1 if the ssh ran OK or 0 otherwise. In case of failures, use $! to do get info." Note the tense and order. $! is meaningless unless run_ssh() returned a failure code. It wouldn't return a failure code if the SSH session was started successfully, and doesn't return success until and unless it was started successfully.

$! is absolutely meaningless regarding the success of run_ssh(), as it will not get populated by run_ssh() except on failure.

Why do you seem to think that run_ssh() is run asynchonously and does not block? It's the SSH connection that's supposed to be in a separate process per the docs, not run_ssh() itself.

  • Comment on Re^4: Problem with Net::SSH::Expect on unavailable hosts

Replies are listed 'Best First'.
Re^5: Problem with Net::SSH::Expect on unavailable hosts
by jrsimmon (Hermit) on Jul 01, 2009 at 22:14 UTC
    From Expect.pm in the Net::SSH package:
    sub run_ssh { my Net::SSH::Expect $self = shift; #(clipped setting up of user options and flags) my $exp = new Expect(); #(clipped setting of Expect options based on user opts/flags) my $success = $exp->spawn($ssh_string); return (defined $success); }
    $success contains the return value of the spawn method in the Expect object. The spawn method in Expect forks the ssh process. As soon as this method is called, ssh is off and running (and we'd better be thinking in async mode). From what I can tell, the spawn method in Expect only returns undef if fork fails or if it's unable to sync with the child process immediately after the fork (I assume to confirm that the process started). Except for those two instances, the eventual return value of run_ssh is going to be positive.

    I'll admit, I have some trouble reading the Expect module. So perhaps I'm missing something...but my experience with this module and the quick test script I wrote earlier both support my conclusion.