a.bat >a.txt
a.txt就是你要的

解决方案 »

  1.   

    对于这个问题,我只能谈谈思路:
    用多线程;启动dos程序时,捕捉屏幕的程序(有一个API可以解决)但由于DOS信息很快闪过,所以要控制截屏,用多线程.the API is
    bitblt(),example:
    bitblt(image.canvas.handle,0,,image.wieth,image.height,getdc(0),0,0,scrcopy)
      

  2.   

    例子:运行 'chkdsk.exe c:\' 并且 显示其输出结果到 Memo 中!procedure RunDosInMemo(DosApp:String;AMemo:TMemo);
    const ReadBuffer = 2400;  
    var
      Security : TSecurityAttributes;
      ReadPipe,WritePipe : THandle;
      start : TStartUpInfo;
      ProcessInfo : TProcessInformation;
      Buffer : Pchar;
      BytesRead : DWord;
      Apprunning : DWord;
    begin
      With Security do
      begin
        nlength := SizeOf(TSecurityAttributes);
        binherithandle := true;
        lpsecuritydescriptor := nil;
      end;
      if Createpipe (ReadPipe, WritePipe, @Security, 0) then
      begin
        Buffer := AllocMem(ReadBuffer + 1);
        FillChar(Start,Sizeof(Start),#0);
        start.cb := SizeOf(start);
        start.hStdOutput := WritePipe;
        start.hStdInput := ReadPipe;
        start.dwFlags := STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW;
        start.wShowWindow := SW_HIDE;
        if CreateProcess(nil,PChar(DosApp),@Security,@Security,true,NORMAL_PRIORITY_CLASS,
                 nil,nil,start,ProcessInfo) then
        begin
          repeat
            Apprunning := WaitForSingleObject(ProcessInfo.hProcess,100);
            Application.ProcessMessages;
          until (Apprunning <> WAIT_TIMEOUT);
          Repeat
            BytesRead := 0;
            ReadFile(ReadPipe,Buffer[0],ReadBuffer,BytesRead,nil);
            Buffer[BytesRead]:= #0;
            OemToAnsi(Buffer,Buffer);
            AMemo.Text := AMemo.text + String(Buffer);
          until (BytesRead < ReadBuffer);
        end;
        FreeMem(Buffer);
        CloseHandle(ProcessInfo.hProcess);
        CloseHandle(ProcessInfo.hThread);
        CloseHandle(ReadPipe);
        CloseHandle(WritePipe);
      end;
    end;调用实例:RunDosInMemo('chkdsk.exe c:\',Memo1);
      

  3.   

    在你的程序里面执行批处理文件Xx.bat,xx.bat里面包含了你在DOS下运行的各种命令,在文件中导出运行结果:
    xx.bat中的内容:如: scandisk c: > c:\Result.txt