#include
int main()
;process_information pi;
tchar szcommandline = text("c://o//yes");
seterrormode( sem_nogpfaulterrorbox );
bool bcreateret = createprocess(null, szcommandline, null, null, false, 0, null, null, &si, π);
if (!bcreateret)
return 0;
dword dwret = waitforsingleobject(pi.hprocess, 2000);
terminateprocess(pi.hprocess, 0);
}建立程序有system("")函式,但該函式有如下限制:
1、函式執行後,建立子程序,父程序必須掛起直到子程序執行結束。
2、子程序如果出現異常,如執行崩潰、死迴圈等情況,父程序無法通過超時詢問等方式來處理。
所以,在windows下編寫可靠程式時,應避免使用system函式,而應該使用createprocess函式。
以上**段建立子程序,通過seterrormode設定標記位,使得子程序執行崩潰時不彈出除錯資訊,否則,父程序即使通過
詢問超時來關閉子程序也無法完成關閉,因為除錯程式也引用了該子程序。
以上api詳細資訊參見msdn
Python subprocess 建立子程序
python提供多個建立子程序的模組,我比較習慣使用subprocess模組,因為在python手冊中有這樣一段話 this module intends to replace several other,older modules and functions,such as os.system o...
Python subprocess 建立子程序
python提供多個建立子程序的模組,我比較習慣使用subprocess模組,因為在python手冊中有這樣一段話 this module intends to replace several other,older modules and functions,such as os.system o...
Python在windows下的分布式程序
在thread和process中,應當優選process,因為process更穩定,而且,process可以分布到多台機器上,而thread最多只能分布到同一臺機器的多個cpu上。python的multiprocessing模組不但支援多程序,其中managers子模組還支援把多程序分布到多台機器上...