Guest User

Untitled

a guest
Aug 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. Getting the return value of a command executed using backticks in Perl
  2. output=`command`
  3. retcode=$?
  4.  
  5. $output=`command`
  6. $retcode=???
  7.  
  8. $? The status returned by the last pipe close, backtick ("``") command, successful call to wait() or waitpid(), or from the
  9. system() operator. This is just the 16-bit status word returned by the traditional Unix wait() system call (or else is made up
  10. to look like it). Thus, the exit value of the subprocess is really ("$? >> 8"), and "$? & 127" gives which signal, if any, the
  11. process died from, and "$? & 128" reports whether there was a core dump. (Mnemonic: similar to sh and ksh.)
  12.  
  13. Additionally, if the "h_errno" variable is supported in C, its value is returned via $? if any "gethost*()" function fails.
  14.  
  15. If you have installed a signal handler for "SIGCHLD", the value of $? will usually be wrong outside that handler.
  16.  
  17. Inside an "END" subroutine $? contains the value that is going to be given to "exit()". You can modify $? in an "END"
  18. subroutine to change the exit status of your program. For example:
  19.  
  20. END {
  21. $? = 1 if $? == 255; # die would make it 255
  22. }
  23.  
  24. Under VMS, the pragma "use vmsish 'status'" makes $? reflect the actual VMS exit status, instead of the default emulation of
  25. POSIX status; see "$?" in perlvms for details.
  26.  
  27. Also see "Error Indicators".
Add Comment
Please, Sign In to add comment