我有一個Perl腳本調用另一個腳本。 Perl腳本應該傳播腳本的返回代碼,但似乎將其調用者(Java應用程序)返回爲零,以致明確地調用。當我使用非零參數顯式調用exit時,爲什麼我的Perl腳本會返回零返回碼?
代碼和輸出如下(我知道<=>
可以/應該是!=
但是這就是我):
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;
}
的輸出,我從我的Java擁有的是:
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.
假設你的意思'shift'在' $ scriptReturnCode = $ scriptReturnCode >> 8;' – 2010-04-21 10:57:51
是的 - 更新。 – DVK 2010-04-21 11:09:53
理想情況下,明確添加退出代碼在8(低)位截斷,因此返回256而不是預期的1結束爲0.同樣,返回257結束爲1等。 – ysth 2010-04-21 14:40:40