Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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 ( [id://956116]=note: print w/replies, xml ) Need Help??


in reply to Re: 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

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.

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

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

    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://956116]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-23 14:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found