![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| calling Perl from C | pkusumam | High Level Programming | 3 | 04-01-2009 05:16 AM |
| [PERL] Running unix commands within Perl Scripts | userix | Shell Programming and Scripting | 1 | 05-28-2008 07:06 PM |
| rsh commands not getting executed from Solaris 10 System to AIX System | jumadhiya | SUN Solaris | 25 | 01-22-2007 05:26 AM |
| Unix commands in perl script | athri | UNIX for Dummies Questions & Answers | 1 | 07-14-2006 10:31 AM |
| URL calling in PERL | DeepakXavier | Shell Programming and Scripting | 1 | 01-04-2006 11:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Perl calling unix system commands
Code:
if ( system ("/bin/cat $File1 >> $File2") ) {
print("#WARNING RAISED : /bin/cat File1 >> File2 - FAILURE!\n"); }
the perl code tell the system to cat file 1 into file 2, if command fails, print the warning statement? I am a little confused by the test condition: if ( system ("/bin/cat $File1 >> $File2") ) Is it testing for successful writing or unsuccessful writing ? |
|
||||
|
Quote:
You do not have to be confused by the semantics of this usage. It appears bizarre, but it actually works that way because system() returns a value that depends on the return value of the command executed. If you read the perldoc for system() you will find that the actual return status is encoded in the least significant 8 bits, and higher bits will be set in the event of other errors. In general, most Unix shell commands have the convention of 0 return status being successful, while other values reflect error status. Therefore, the construct you quoted actually means to detect anything non-zero, that indicates error status. Of course it deviates from typical programming practice that zero is considered false, error, or anything like NULL. |
|
||||
|
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|