CreateProcess引數傳遞

2022-03-23 01:17:21 字數 1322 閱讀 7778

引數傳遞是很奇怪,有時候會無法啟動,比如:

createprocess("c:\\a.exe","aa bb cc",....),顯示出錯

通過createprocess("c:\\a.exe", "\"c:\\a.exe\" c:\\a.exe aa bb cc"...)即可.

handle hread,hwrite;

security_attributes sa;

sa.nlength=sizeof

(security_attributes);

sa.binherithandle=true

; sa.lpsecuritydescriptor=null;

if(!::createpipe(&hread,&hwrite,&sa,0))

startupinfo si;

si.cb=sizeof

(startupinfo);

getstartupinfo(&si);

si.dwflags=startf_useshowwindow|startf_usestdhandles;

si.wshowwindow=sw_hide;//

這裡設定是否顯示dos視窗

si.hstderror=hwrite;

si.hstdoutput=hwrite;

si.hstdinput=getstdhandle(std_input_handle);

process_information pi;

lpstr lpszcmdline="

cmd sname ...

";//

這裡你自己修改吧。

if(!createprocess(null,lpszcmdline,null,null,true,0,null,0,&si,&pi))

closehandle(hwrite);

if(waitforsingleobject(pi.hprocess,5000)==wait_timeout)

char buf[4096]=;

dword bytes;

if(::readfile(hread,buf,4095,&bytes,null)==null)//

讀取程式輸出

else

closehandle(pi.hthread);

closehandle(pi.hprocess);

closehandle(hread);

return

true

;用createprocess建立程序,用管道讀取程式輸出。用getexitcodeprocess讀取程式退出**

另外參考:

CreateProcess引數傳遞細節

背景 用createprocess呼叫win32控制台程式,引數傳遞win32程式接受不到。cstring strfullpath t d test.exe cstring strcmdline t param startupinfo si process information pi bool b...

CreateProcess函式使用

startupinfo infostart process information infoprocess memset infostart,0,sizeof infostart infostart.cb sizeof startupinfo infostart.dwflags startf use...

CreateProcess 終止程序

最近需要用到,稍微研究了下。1.供createprocess啟動的程序test.exe,只是列印出引數而已。include stdafx.h include include include using namespace std int main int argc,char argv 程式 incl...