使用ShellExecuteEx(..)获取python脚本,并使用从python main返回值的python脚本系统出口(0)成功或其他错误值。如何读取python脚本退出代码?你知道吗
在启动应用程序后,我一直在使用MsgWaitForMultipleObjects(…)等待完成脚本,然后调用getexitdeprocess(…),原因是我总是从getexitdeprocess(…)读取值1
Python代码:
def main():
time.sleep(10)
logger.info("************The End**********")
return (15)
if __name__ == "__main__":
sys.exit(main())
<强> C++代码:< /强>
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
;
else
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();
}
在这段代码中,作为带15的Python脚本,我希望从GetExitCodeProcess的dwCode中读取15(rSEI.h进程,&dwCode)?你知道吗
感谢你在这方面的帮助。。。你知道吗
Python代码示例:
用
.py
作为后缀而不是.Exe
命名Python脚本文件,例如"python.py"
将路径值赋给
SHELLEXECUTEINFO.lpDirectory
,并在此处将SHELLEXECUTEINFO.lpParameters
设置为NULL
。 或者将路径和文件组合赋给SHELLEXECUTEINFO.lpVerb
,如"Path\\python.py"
<强> C++代码示例:>/P>
相关问题 更多 >
编程相关推荐