将 java 命令退出代码传递给批处理错误级别



我正在运行一个批处理,要用我们的一个自动化过程执行,在这个批处理中,我调用了一个java命令(应用程序(。自动处理应查看最终退出代码,并确定其成功是否 = 0,这将是一个失败。在这种情况下,它确实确定并批量恢复到下一行,就像什么都没发生一样。

这是批次

@ECHO Off
SET Talend_Job=%1%
E:
CD E:OperationsBatchServicesTalendBatchesTalend_AutoSys_Integrationscripts
for /f "tokens=2" %%2 in (E:OperationsBatchServicesTalendBatchesTalend_AutoSys_IntegrationscriptsResults%Talend_Job%.txt) do (
set  LABEL_OR_ID=%%2
goto gotrev
)
:gotrev
echo  LABEL_OR_ID is %LABEL_OR_ID%
java -jar E:OperationsBatchServicesTalendBatchesTalend_AutoSys_IntegrationscriptsTalendTacTasks-1.0.1.jar ^ get_task_status ^ http://dc01talndtlv01.mycompany.loc:8080/org.talend.administrator/ ^ %LABEL_OR_ID%
set exitcode=%ERRORLEVEL%
echo %exitcode%
echo %ERRORLEVEL%
exit /B %ERRORLEVEL%
----------my results log ---------------
C:UsersAutosysdevsvc>SET Talend_Job=autosys_talend_test_with_error 
C:UsersAutosysdevsvc>E:
E:>CD E:OperationsBatchServicesTalendBatchesTalend_AutoSys_Integrationscripts 
E:OperationsBatchServicesTalendBatchesTalend_AutoSys_Integrationscripts>for /F "tokens=2" %2 in (E:OperationsBatchServicesTalendBatchesTalend_AutoSys_IntegrationscriptsResultsautosys_talend_test_with_error.txt) do (
set  LABEL_OR_ID=%2  
goto gotrev 
) 
E:OperationsBatchServicesTalendBatchesTalend_AutoSys_Integrationscripts>(
set  LABEL_OR_ID=1529519219417_Y6RLK  
goto gotrev 
) 
E:OperationsBatchServicesTalendBatchesTalend_AutoSys_Integrationscripts>echo  LABEL_OR_ID is 1529519219417_Y6RLK 
LABEL_OR_ID is 1529519219417_Y6RLK
E:OperationsBatchServicesTalendBatchesTalend_AutoSys_Integrationscripts>java -jar E:OperationsBatchServicesTalendBatchesTalend_AutoSys_IntegrationscriptsTalendTacTasks-1.0.1.jar  get_task_status  http://dc01talndtlv01.mycompany.loc:8080/org.talend.administrator/  1529519219417_Y6RLK 
ERROR: Execution Status: JOB_ERROR: Job ended with error(s) - Job Exit Code: 1
E:OperationsBatchServicesTalendBatchesTalend_AutoSys_Integrationscripts>echo Exitcode= 
Exitcode=
E:OperationsBatchServicesTalendBatchesTalend_AutoSys_Integrationscripts>set exitcode=0 
E:OperationsBatchServicesTalendBatchesTalend_AutoSys_Integrationscripts>echo ERRORLEVEL=0 
ERRORLEVEL=0
E:OperationsBatchServicesTalendBatchesTalend_AutoSys_Integrationscripts>exit /B 0 

%ERRORLEVEL%应包含批处理文件执行的最后一个命令的退出代码 - 在本例中为jar文件的执行。

如您的输出所示,您对 java 可执行文件的调用导致合法返回代码0

(请注意,在 java 调用之后,您确实有一个echo命令,但此 echo 调用不会替换%ERRORLEVEL%值(。

正如 schtever 和 Jim Garrison 所提到的,由于您的 java 应用程序成功终止而没有任何异常,因此它返回的返回代码取决于您的 java 应用程序退出代码 - 如果未通过System.exit(1)明确说明,则会0

引用:

  • 窗口批处理脚本:返回代码
  • 如何从 Windows 命令行获取应用程序退出代码?
  • 错误级别
  • 与 %错误级别% 与感叹号 错误级别感叹号
  • 如何在Windows批处理文件中获取Java程序的退出状态
  • 从批处理文件中的 Java 应用程序获取退出代码
  • 是否可以使用 Java 程序的退出代码来检测磁盘空间不足异常?

最新更新