如何调用DOS命令?(50分)

  • 主题发起人 yanghx_yhx
  • 开始时间
Y

yanghx_yhx

Unregistered / Unconfirmed
GUEST, unregistred user!
请教各位高手:<br>在DELPHI中如何调用dos应用程序中的命令?如在DELPHI中如何调用DOS压缩程序PKZIP中的多个文件压缩命令?<br><br>非常感谢,非常急盼回复!!!
 
winexec(PChar('C:/command.com/?'),SW_NORMAL);
 
用Winexec可以,但是要注意的是Winexec并不等待程序执行完,而是直接跳到下一步,<br>推荐用如下代码:<br>function WinExecAndWait32(FileName:String; Visibility :integer):integer;<br>//调用其它程序并等待<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 securityattributes }<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to thread securityattributes }<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>
 
接受答案了.
 
顶部