GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  Perl
Go To First  |  Previous Question  |  Next Question 
 Perl  |  Question 53 of 61    Print  
How do you you check the return code of a command in Perl
Suppose you run a program/script in Perl:

system("./server ....");

How will you check the return code?



  
Total Answers and Comments: 3 Last Update: June 22, 2009     Asked by: mpathak 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
December 06, 2007 12:20:22   #1  
perl_guy Member Since: December 2007   Contribution: 1    

RE: How do you you check the return code of a command in Perl

system calls *traditionally* returns 0 when successful and 1 when it fails.

system ( cmd ) && die "Error - could run cmdn";


 
Is this answer useful? Yes | No
July 11, 2008 17:16:26   #2  
kglukhov Member Since: July 2008   Contribution: 2    

RE: How do you you check the return code of a command in Perl
# Retrieve the higher byte of the two-byte return code

my $ret system("./server") >> 8;

 
Is this answer useful? Yes | No
June 22, 2009 04:33:36   #3  
amitkshirsagar Member Since: June 2009   Contribution: 3    

RE: How do you you check the return code of a command in Perl
$r system("command .. e.g. search");
print"r is $rn";

Here if $r is 0 that means command has executed successfully.
Any other value means command has failed.


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape