如何获得dos输出.在delphi2009中使用vista
发布时间:2020-12-13 20:34:36 所属栏目:Windows 来源:网络整理
导读:我用delphi来获取dos输出. 什么原因导致 http://delphi.about.com/cs/adptips2001/a/bltip0201_2.htm的代码无法在vista上使用delphi2009?但它适用于XP中的D7.我不知道要修改哪个部分才能使其正常工作. DelphiDabbler has a solution,虽然我没有亲自测试过:
我用delphi来获取dos输出.
什么原因导致 http://delphi.about.com/cs/adptips2001/a/bltip0201_2.htm的代码无法在vista上使用delphi2009?但它适用于XP中的D7.我不知道要修改哪个部分才能使其正常工作.
DelphiDabbler has a solution,虽然我没有亲自测试过:
function GetDosOutput(CommandLine: string; Work: string = 'C:'): string; var SA: TSecurityAttributes; SI: TStartupInfo; PI: TProcessInformation; StdOutPipeRead,StdOutPipeWrite: THandle; WasOK: Boolean; Buffer: array[0..255] of AnsiChar; BytesRead: Cardinal; WorkDir: string; Handle: Boolean; begin Result := ''; with SA do begin nLength := SizeOf(SA); bInheritHandle := True; lpSecurityDescriptor := nil; end; CreatePipe(StdOutPipeRead,StdOutPipeWrite,@SA,0); try with SI do begin FillChar(SI,SizeOf(SI),0); cb := SizeOf(SI); dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES; wShowWindow := SW_HIDE; hStdInput := GetStdHandle(STD_INPUT_HANDLE); // don't redirect stdin hStdOutput := StdOutPipeWrite; hStdError := StdOutPipeWrite; end; WorkDir := Work; Handle := CreateProcess(nil,PChar('cmd.exe /C ' + CommandLine),nil,True,PChar(WorkDir),SI,PI); CloseHandle(StdOutPipeWrite); if Handle then try repeat WasOK := ReadFile(StdOutPipeRead,Buffer,255,BytesRead,nil); if BytesRead > 0 then begin Buffer[BytesRead] := #0; Result := Result + Buffer; end; until not WasOK or (BytesRead = 0); WaitForSingleObject(PI.hProcess,INFINITE); finally CloseHandle(PI.hThread); CloseHandle(PI.hProcess); end; finally CloseHandle(StdOutPipeRead); end; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- win7旗舰版怎么降级到专业版
- windows-server-2008 – 丢弃的数据包,仅接收,仅
- windows-server-2012-r2 – 如何将FreeNAS设置为
- IIS5?HTTP500内部错误分析及解决办法
- 如何停止使用MinGW(g)编译的程序在Windows中打开
- .net – 如何使用断点调试Windows服务?
- 在Windows上使用NodeJS上的path.join创建URL
- windows-server-2008 – 如何在powershell脚本中
- Microsoft Visual Studio 2012无法在c#文件中设置
- windows – 强制mingw32-make忽略sh
热点阅读