Is there an equivalent in Net::SSH::Expect 1.09 for "collect_exit_code"

251 views Asked by At

I came across this link: Exit status code for Expect script called from Bash but it did not help me. As I was looking to get the exit status code from a command run remotely, I came across cpan documentation for Net::SSH::Expect 0.08 which has "collect_exit_code" and "last_exit_code" methods, which is exactly what I'd like to use today, however, I'm unable to find a suitable replacement when running 1.09.

I'd like to keep it simple, such as:

$ssh_devel_exp->collect_exit_code(1);
$ssh_devel_exp->send("sudo make");
if ($ssh_devel_exp->last_exit_code()) { etc. and so forth... };

But, I cannot think of a simple way to get the exit status when running a command through Net Expect without methods similar to these.

I do not believe switching to Fabric is the answer for this issue; this is a perl application and I need to stick with Perl.

Thanks in advance.

1

There are 1 answers

1
user1126070 On

Did you tried to call the underlying expect object?

$ssh_devel_exp->{expect}->collect_exit_code(1);
$ssh_devel_exp->send("sudo make");
if ($ssh_devel_exp->{expect}->last_exit_code()) { etc. and so forth... };

if nothing else helps you could create a small shell script that execute your commands and report back the exitstatus on stderr.