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

HI,
I have a general question regarding the Net::Telnet perl module. I was wondering if there was any way for a perl program, which uses this module, to recieve an exit status from the success or failure of the $object->cmd() method. I have a script that cats a file on a remote machine and I would like to be able to determine if the file exists or not so I can display the appropriate error message or output. I have read carefully through the documentation for the module and am still trying to make sense of it and determine if this type of action is possible. If anyone knows if this is possible or not, I would be very greatful for any input. Thanks! Joe

Replies are listed 'Best First'.
Re: Exit status of Net::Telnet question
by Mr_Person (Hermit) on Jun 20, 2003 at 21:27 UTC
    If you're using Bash or similar for the shell on the other end, how about doing:
    my @result = $object->cmd('test -f foo.txt; echo $?')
    Because in Bash $? holds the exit value of the last command, and test -f checks to see if the file given exists and is a regular file, $result[0] should contain either a 1 (file does not exist) or a 0 (file does exist). After you determine that, you can cat your file or display the appropriate error.
      This is an interesting approach. I never actually thought to have the shell do the work. Thanks for the input.
Re: Exit status of Net::Telnet question
by phydeauxarff (Priest) on Jun 20, 2003 at 21:06 UTC
    have you tried just using getline? you should be able to do $line=$obj->getline(); after you issue your cat command and then eval what is returned.
      Thanks! I was not aware of that function. I will definately have to look into it. I appreciate your help.