使用ShellExecuteEx(...)来午餐一个python脚本和python脚本在成功或其他错误值时使用sys.exit(0)从python main返回一个值。如何读取python脚本的退出代码?
在启动应用程序后,通过使用MsgWaitForMultipleObjects(...)等待完成脚本,然后调用GetExitCodeProcess(...),由于某些原因,我总是从getExitCodeprocess(...)读取值1。
Python Code:
def main():
time.sleep(10)
logger.info("************The End**********")
return (15)
if __name__ == "__main__":
sys.exit(main())
C++ Code:
SHELLEXECUTEINFO rSEI = { 0 };
rSEI.cbSize = sizeof(rSEI);
//rSEI.lpVerb = "runas";
rSEI.lpVerb = "open";
rSEI.lpFile = "python.Exe";
rSEI.lpParameters = LPCSTR(path.c_str());
rSEI.nShow = SW_NORMAL;
rSEI.fMask = SEE_MASK_NOCLOSEPROCESS;
if (ShellExecuteEx(&rSEI)) // you should check for an error here
errorMessageID = GetLastError(); //MessageBox("Error", "Status", 0);
WORD nStatus;
MSG msg; // else process some messages while waiting...
while (TRUE)
nStatus = MsgWaitForMultipleObjects(1, &rSEI.hProcess, FALSE, INFINITE, QS_ALLINPUT); // drop through on user activity
if (nStatus == WAIT_OBJECT_0)
{ // done: the program has ended
break;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
DispatchMessage(&msg);
//MessageBox("Wait...", "Status", 0);
} // launched process has exited
DWORD dwCode=0;
if (!GetExitCodeProcess(rSEI.hProcess, &dwCode)) //errorvalue
DWORD lastError = GetLastError();
In this code as Python script exiting with 15, I am expecting to read 15 from dwCode from GetExitCodeProcess(rSEI.hProcess, &dwCode)?
感谢你们在这方面的帮助...