执行命令行并等待完成(使用WaitForSingleObject达到目的)

function TDMDb.WaitExeFinish(const sCmdName: string):boolean;
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
b:boolean;
begin
// 初始化
FillChar(StartupInfo, SizeOf(StartupInfo), );
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := SW_HIDE; // 隐藏执行 // 执行命令行
b:=CreateProcess(nil, PWideChar(sCmdName), nil, nil, False, , nil, nil, StartupInfo, ProcessInfo); // 等待执行完成
with ProcessInfo do
begin
CloseHandle(hThread);
WaitForSingleObject(hProcess, INFINITE);
CloseHandle(hProcess);
end; // 返回
Result := b;
end;

http://blog.csdn.net/shuaihj/article/details/8890419

上一篇:git 从远程拉取代码、推代码的步骤


下一篇:模拟搭建Web项目的真实运行环境(四)