如何从启动此JVM的Windows程序中获取JVM退出代码(来自调用:System.exit(status)的“状态”值)?我尝试使用ShellExecute()调用的结果,但结果(42)与状态的实际值无关。
最佳答案
通过使用ShellExecuteEx而不是ShellExecute启动外部应用程序。
在调用ShellExecuteEx之前,请在ShellExecuteEx函数的参数中启用SEE_MASK_NOCLOSEPROCESS标志。然后,您将在ShellExecuteEx函数的参数的hProcess字段中收到启动进程的句柄。
ShellExecuteEx:http://msdn.microsoft.com/en-us/library/bb762154(VS.85).aspx
然后,使用WaitForSingleObject函数或任何其他WaitFor *函数等待直到外部应用程序终止。
WaitForSingleObject:http://msdn.microsoft.com/en-us/library/ms687032.aspx
然后,使用GetExitCodeProcess函数读取外部进程的退出代码。
GetExitCodeProcess:http://msdn.microsoft.com/en-us/library/ms683189(VS.85).aspx