<?xml version="1.0" encoding="windows-1252"?>
<node id="956117" title="Re: Incorrect value 0 reported in command execution return value variable $?, when trying with expect-&gt;send command" created="2012-02-25 09:20:36" updated="2012-02-25 09:20:36">
<type id="11">
note</type>
<author id="636534">
Perlbotics</author>
<data>
<field name="doctext">
&lt;p&gt;
 Insert this line and the solution will reveal before your weary eyes...
&lt;c&gt;
print "$command ; echo COMMAND_RET:$? | sed 's/^/COMMAND_OUT: /g'; echo -n END_; echo EXPECT\n";
&lt;/c&gt;

Hint:  You need to escape &lt;c&gt;$?&lt;/c&gt;.
&lt;/p&gt;

&lt;p&gt;
Why not get rid of the sed-invocation?
&lt;c&gt;
$exp-&gt;send("$command ; echo 'COMMAND_OUT: COMMAND_RET:'\$?; echo END_EXPECT\n");
&lt;/c&gt; 
Depending on the shells flavour of &lt;c&gt;echo&lt;/c&gt;, you could also get rid of the second echo invocation. 
&lt;/p&gt;</field>
<field name="root_node">
956108</field>
<field name="parent_node">
956108</field>
</data>
</node>
