+

//dos 仿真程序 delphi 窗体实现!
  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, nil, True, 0, nil,
                            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;

最新文章

  1. [LintCode] Find Peak Element 求数组的峰值
  2. 双守护进程(不死service)-5.0系统以下
  3. java并发编程(三)线程挂起,恢复和终止的正确方法
  4. C#通过SSH连接MySql
  5. FFMpeg的码率控制
  6. Android--SQLite的使用
  7. ORACLE 11G R2 修改"用户名"
  8. JPA学习---第五节:日期和枚举等字段类型的JPA映射
  9. Commons IO - IOUtils
  10. Android自定义UI的实现和应用
  11. 百度云是用SOUI开发的产品
  12. 有空就写个C++程序
  13. 在HTML页面中有jQuery实现实现拼图小游戏
  14. NPOI 的使用姿势
  15. Python对List中的元素排序
  16. sublime3 mac : Package Control There are no packages available for installation
  17. Arthas开源项目
  18. div中添加滚动条
  19. [分布式系统学习]阅读笔记 Distributed systems for fun and profit 抽象 之二
  20. 20145317《网络对抗》shellcode注入&Return-to-libc攻击深入

热门文章

  1. StorSimple 简介
  2. cocos2d-x 添加自定义字体---中文,英文
  3. Android4.0 -- UI控件之 Menu 菜单的的使用(四)
  4. C#下多进程共同读写同一文件
  5. Mysql技术内幕-笔记-第三章 查询处理
  6. 我的第一篇Markdown博客
  7. js的 new image()用法[转]
  8. HDU 1568 Fibonacci 数学= = 开篇
  9. ffmpeg的logo, delogo滤镜参数设置
  10. [D3] 14. Line and Area Charts with D3