title: Question on expect perl
body: <p>I am new in expect perl programming and have to write some scripts to automate some tasks. Basically I need to telnet to a unix machine, issue some unix commands and check some outputs. 
  I have written a small script to telnet but I have a doubt on how to check the status of the unix commands. </p>
  
  <pre><code>#!/usr/bin/perl
  use Expect;
  $timeout=10;
  my $exp = Expect-&gt;spawn("telnet test-b -l regress")
      or die "Cannot spawn telnet: $!\n";;
  my $spawn_ok;
  
  $foo1=$exp-&gt;expect($timeout, 'Password:');
  print "######Received Password prompt\n";
  
  $exp-&gt;send("MaRtInI\n");
  print "######Sent password\n";
  
  $foo1=$exp-&gt;expect($timeout, '%');
  print "######Received root prompt\n";
  $exp-&gt;send("cd /var/tmp");
  </code></pre>
  
  <p>I have doubt here on how to check whether the cd command is actually successful, because instead of <code>cd /var/tmp</code> if I give <code>cd /var/temp12</code> (which does-not exist), I am seeing the same result. How can I check whether to unix command which I have sent through cd is actually successful ?</p>