in reply to Re^2: Incorrect value 0 reported in command execution return value variable $?, when trying with expect->send command
in thread Incorrect value 0 reported in command execution return value variable $?, when trying with expect->send command

I'm sorry! On rereading your original post, I realize you are using double quotes:

$exp->send("$command ; echo COMMAND_RET:$? | sed 's/^/COMMAND_OUT: /g +'; echo -n END_; echo EXPECT\n");

So your command is not actually what you send over the wire. Use

my $cmd = "$command ; echo COMMAND_RET:$? | sed 's/^/COMMAND_OUT: /g'; + echo -n END_; echo EXPECT\n"; warn "Sending command [$cmd]"; $exp->send($cmd);

for debugging such issues. Personally, when dealing with interpolating data into strings, I prefer sprintf over plain interpolation:

my $cmd = sprintf q{%s; echo COMMAND_RET:$? | sed 's/^/COMMAND_OUT: /g +'; echo -n END_; echo EXPECT\n}, $command; warn "Sending command [$cmd]"; $exp->send($cmd);
  • Comment on Re^3: Incorrect value 0 reported in command execution return value variable $?, when trying with expect->send command
  • Select or Download Code