need_help21 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Everyone!!
my $telnet = new Net::Telnet ( Timeout=>86400, Errmode=>'die'); $telnet->open('xx.xx.xx.xx'); $telnet->waitfor('/login: $/i'); $telnet->print('xxx'); $telnet->waitfor('/password: $/i'); $telnet->print('xxx'); my $output = $telnet->waitfor('/\$ $/i'); $telnet->print("cd /testdata/BatchValidation/driver"); $output = $telnet->waitfor('/\$ $/i'); $telnet->print("sh $sDriver") or die "cannot execute the sh +ell file"; $telnet->waitfor('/\$ $/i'); my @exit_status = (); @exit_status = $telnet->cmd("echo $?") or warn "ugh\n";; print @exit_status; my $result = $exit_status[0]; print $result; if ($result != '0') { fnShowFormForExecution(); } elsif ($result == '0') { fnShowFormForGettingReport(); }
The value returned by @exit_status = $telnet->cmd("echo $?") is always 0. I don't know why? please someone help !! where i am wrong here??
  • Comment on return value of net:telnet is wrong @exit_status = $telnet->cmd("echo $?")
  • Download Code

Replies are listed 'Best First'.
Re: return value of net:telnet is wrong @exit_status = $telnet->cmd("echo $?")
by moritz (Cardinal) on Nov 29, 2007 at 13:40 UTC
    The Net::Telnet doc suggests that the return value from cmd is a server response, not an exit status as you seem to think.
      hi moritz, thanks for looking into this problem! what should the server response be over here? And if this way i cannot get the result waht is required there.. what could be the possible way to get the exit status of the "sh $sDriver" which i executed on the remote machine. Please help !! any help appreciated!
        I want to thanks BART for his suggestion in CB that the $ sign in "echo $?" should be escaped. This was actually the probelm. Now it has got solved. Thank BART and thanks to all.