Why does my perl script return a zero return code when I explicitly call exit with a non-zero parame
Posted
by Tom Duckering
on Stack Overflow
See other posts from Stack Overflow
or by Tom Duckering
Published on 2010-04-21T10:35:19Z
Indexed on
2010/04/21
10:43 UTC
Read the original article
Hit count: 179
perl
|return-value
I have a perl script which calls another script. The perl script should be propagating the script's return code but seems to be returning zero to its caller (a Java application) desipte the explicit call to exit $scriptReturnCode
.
It's probably something dumb since I'm by no means a perl expert.
Code and output as follows (I realise that <=>
could/should be !=
but that's what I have):
print "INFO: Calling ${scriptDirectory}/${script} ${args}"
$scriptReturnCode = system("${scriptDirectory}/${script} ${args}");
if ( $scriptReturnCode <=> 0 ) {
print "ERROR: The script returned $scriptReturnCode\n";
exit $scriptReturnCode;
} else {
print "INFO: The script returned $scriptReturnCode.\n";
exit 0;
}
The output I have from my Java is:
20/04/2010 14:40:01 - INFO: Calling /path/to/script/script.ksh arg1 arg2
20/04/2010 14:40:01 - Could not find installer files <= this is from the script.ksh
20/04/2010 14:40:01 - ERROR: The script returned 256
20/04/2010 14:40:01 - Command Finished. Exit Code: 0 <= this is the Java app.
© Stack Overflow or respective owner