用CreateProcess怎样等待Dos命令结束?(40分)

  • 主题发起人 主题发起人 Town
  • 开始时间 开始时间
T

Town

Unregistered / Unconfirmed
GUEST, unregistred user!
看了huizhang的说明,查了查帮助,还是不知道哪个参数是管这个的.<br>还是老问题:<br>&nbsp; &nbsp;运行 &nbsp;dir &gt;test.txt<br>用TStringList.LoadFromFile('test.txt');<br>怎样等到Dos命令结束了再运行LoadFromFile?<br><br>又一次全部家产都拿走了,我的分数总是很少:(
 
好奇怪的想法,在Windows9x&amp;NT下爲什麽生成Dos的線程,<br>你生成了麽,據我所知,這種情況下是不允許你創建DOS線程的<br>(32位操作系統的特性)
 
CreateProcess不是要返回一个进程句柄和一个线程句柄吗?<br>用WaitForSingleObject(hThread)就可以了.
 
前几天看uddf的时候,发现了如下的源程序:<br>From: Noel Rice &lt;nrice@ix.netcom.com&gt;<br><br>A: Here is the 16 bit version:<br><br><br>--------------------------------------------------------------------------------<br><br>uses Wintypes,WinProcs,Toolhelp,Classes,Forms;<br><br>Function WinExecAndWait(Path : string; Visibility : word) : word;<br>var<br>&nbsp; InstanceID : THandle;<br>&nbsp; PathLen : integer;<br>begin<br>&nbsp; { inplace conversion of a String to a PChar }<br>&nbsp; PathLen := Length(Path);<br>&nbsp; Move(Path[1],Path[0],PathLen);<br>&nbsp; Path[PathLen] := #00;<br>&nbsp; { Try to run the application }<br>&nbsp; InstanceID := WinExec(@Path,Visibility);<br>&nbsp; if InstanceID &lt; 32 then { a value less than 32 indicates an Exec error }<br>&nbsp; &nbsp; &nbsp;WinExecAndWait := InstanceID<br><br>&nbsp; else begin<br>&nbsp; &nbsp; Repeat<br>&nbsp; &nbsp; &nbsp; Application.ProcessMessages;<br>&nbsp; &nbsp; until Application.Terminated or (GetModuleUsage(InstanceID) = 0);<br>&nbsp; &nbsp; WinExecAndWait := 32;<br>&nbsp; end;<br>end;<br><br>--------------------------------------------------------------------------------<br>Here is the 32 bit version:<br><br><br>--------------------------------------------------------------------------------<br><br>function WinExecAndWait32(FileName:String; Visibility : integer):integer;<br>var<br>&nbsp; zAppName:array[0..512] of char;<br>&nbsp; zCurDir:array[0..255] of char;<br>&nbsp; WorkDir:String;<br>&nbsp; StartupInfo:TStartupInfo;<br>&nbsp; ProcessInfo:TProcessInformation;<br>begin<br>&nbsp; StrPCopy(zAppName,FileName);<br>&nbsp; GetDir(0,WorkDir);<br>&nbsp; StrPCopy(zCurDir,WorkDir);<br>&nbsp; FillChar(StartupInfo,Sizeof(StartupInfo),#0);<br>&nbsp; StartupInfo.cb := Sizeof(StartupInfo);<br><br>&nbsp; StartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br>&nbsp; StartupInfo.wShowWindow := Visibility;<br>&nbsp; if not CreateProcess(nil,<br>&nbsp; &nbsp; zAppName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ pointer to command line string }<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to process security attributes }<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to thread security attributes }<br>&nbsp; &nbsp; false, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { handle inheritance flag }<br>&nbsp; &nbsp; CREATE_NEW_CONSOLE or &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ creation flags }<br>&nbsp; &nbsp; NORMAL_PRIORITY_CLASS,<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to new environment block }<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to current directory name }<br>&nbsp; &nbsp; StartupInfo, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to STARTUPINFO }<br>&nbsp; &nbsp; ProcessInfo) then Result := -1 { pointer to PROCESS_INF }<br><br>&nbsp; else begin<br>&nbsp; &nbsp; WaitforSingleObject(ProcessInfo.hProcess,INFINITE);<br>&nbsp; &nbsp; GetExitCodeProcess(ProcessInfo.hProcess,Result);<br>&nbsp; end;<br>end;<br>
 
多人接受答案了。
 
后退
顶部