Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by Corion (Patriarch)
on Feb 25, 2012 at 13:49 UTC ( [id://956110]=note: print w/replies, xml ) Need Help??


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

I don't know much about Expect, but what you are calling as command is really calling a shell executable and passing it that command. I venture that whatever shell you are using is not passing the exit code upwards, or, as a shell, is actually running OK and thus exits with exit code 0. Also see the documentation of Expect on ->exitstatus maybe.

  • Comment on Re: Incorrect value 0 reported in command execution return value variable $?, when trying with expect->send command
  • Download Code

Replies are listed 'Best First'.
Re^2: Incorrect value 0 reported in command execution return value variable $?, when trying with expect->send command
by Davewhite (Acolyte) on Feb 25, 2012 at 14:10 UTC

    The same piece of code is working fine and returning correct return when executed on the same shell manually

    I was thinking that all the collective input to expect->send command also executes on the some shell, so it should contain the command execution status value rather than the shell exit value, as the "echo COMMAND_RET:$?" gets executed before the shell exit.

      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);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://956110]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-18 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found