1

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.

Community
  • 1
  • 1
harperville
  • 6,921
  • 8
  • 28
  • 36

1 Answers1

0

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.

user1126070
  • 5,059
  • 1
  • 16
  • 15
  • Hmm, perhaps I should have included the creation of the object...I create the object like so: `my $ssh_devel_exp=Net::SSH::Expect->new(host=>$devel_server,user=>$USER,password=>$PASS_M,raw_pty=>1);` That makes the 'call' ("->{expect}") superfluous, correct? When I try your additions, I get: ERROR: cannot find method `collect_exit_code' in class Expect at /usr/lib/cgi-bin/menu.pl line 217. – harperville Sep 05 '12 at 14:05