在Delphi中调用Dos程序后会出现一个窗体,通过对WinExeC或CreateProgress中的参数可以屏蔽这个窗口的出现,但是怎样输出这个窗体的信息到一个文件中呢?
    在Win98下,我先生成了一个内容为"ExeName.exe > Dest.txt"的Bat文件,然后运行这个Bat文件就可以把ExeName.exe输出到窗口的信息获取到Dest.txt中.但是在Win2000/XP中这个办法很慢而且有时会出错.在Win2000/XP中可以直接用WinExeC执行命令行"ExeName.exe > Dest.txt",可以达到同样的效果,但是在Win98下根本不行.
    请问各位高人:怎样可以有一个在Win9X和Win2000/XP中都很好的办法呢?我猜是应该调用API函数CreateProgress或其他

解决方案 »

  1.   

    用'ExeName.exe >> Dest.txt'
      

  2.   

    同意楼上
    exe >data.txt
      

  3.   

    Win98下面无法??那你就  ExeName.exe > c:\dest.txt ,这样地址就绝对化了
      

  4.   

    我试过了在Win98和2000/XP下都没有问题,应该是其它因素所导致。我还发现用">"和">>"会产生不同的结果,用">"时如果记录文件已存在就会覆盖原有内容,而用">"会在原有文件上添加纪录。:)
      

  5.   

    firetoucher(风焱) & bluenightsky() & Eastunfail(恶鱼杀手) & Odayfans(Odayfans):
        我不知道你们说的是什么意思,是在Bat文件中写 "ExeName.exe > Dest.txt",还是在Winexec中调用.如果是在WinExec中调用的话,正如我在提问中说的,Win98下确实不行(ExeName自己还有参数要传递),因为Win98的Dos是独立的,用WinExec来这样调用,等于给Dos程序ExeName传送了一个参数,所以不行.但是在Win2000/XP中,Dos是一个虚拟机,用WinExec调用,相当于给Dos虚拟机程序传递了一个参数,然后Dos虚拟机再截取参数,执行程序,所以在Win2000/XP中可以.
        如果是在Bat文件中写的话,Win2000/XP会很慢而且不稳定,原因可能是因为它们和Dos兼容的不好.
        我再试一试,看看对不对.
        各位高人如果还有办法,还望多多指教,最好给个例子(ExeName.exe自己也有参数,比如:Masm c:\cc.asm /Fl 等),在下洗耳恭听.
      

  6.   

    看这个
    http://www.csdn.net/develop/article/18/18338.shtm
      

  7.   

    可用管道的方法!看看如下代码,测试过没问题的.将数据输入到memo1中,当然,你也可改动到其它流中!procedure TForm1.btnRunClick(Sender: TObject);
    var
    hReadPipe,hWritePipe:THandle;
    si:STARTUPINFO;
    lsa:SECURITY_ATTRIBUTES;
    pi:PROCESS_INFORMATION;
    mDosScreen:String;
    cchReadBuffer:DWORD;
    ph:PChar;
    fname:PChar;
    i,j:integer;
    begin
    fname:=allocmem(255);
    ph:=AllocMem(5000);
    lsa.nLength :=sizeof(SECURITY_ATTRIBUTES);
    lsa.lpSecurityDescriptor :=nil;
    lsa.bInheritHandle :=True; if CreatePipe(hReadPipe,hWritePipe,@lsa,0)=false then
    begin
    ShowMessage('Can not create pipe!');
    exit;
    end;
    fillchar(si,sizeof(STARTUPINFO),0);
    si.cb :=sizeof(STARTUPINFO);
    si.dwFlags :=(STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW);
    si.wShowWindow :=SW_HIDE;
    si.hStdOutput :=hWritePipe;
    StrPCopy(fname,EditFilename.text); if CreateProcess( nil, fname, nil, nil, true, 0, nil, nil, si, pi) = False then
    begin
    ShowMessage('can not create process');
    FreeMem(ph);
    FreeMem(fname);
    Exit;
    end; while(true) do
    begin
    if not PeekNamedPipe(hReadPipe,ph,1,@cchReadBuffer,nil,nil) then break;
    if cchReadBuffer<>0 then
    begin
    if ReadFile(hReadPipe,ph^,4096,cchReadBuffer,nil)=false then break;
    ph[cchReadbuffer]:=chr(0);
                                    Memo1.Lines.Add(ph);
    end
    else if(WaitForSingleObject(pi.hProcess ,0)=WAIT_OBJECT_0) then break;
    Sleep(100);
    end; ph[cchReadBuffer]:=chr(0);
               Memo1.Lines.Add(ph);
    CloseHandle(hReadPipe);
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
    CloseHandle(hWritePipe);
    FreeMem(ph);
    FreeMem(fname);
    end;