DOS?? 哈哈哈 要是DOS就不用那么麻烦了,管道输出到你程序界面上就行了<br>给你个例子,也是从别人那抄来改的,放个memo、edit、button<br>默认是执行命令行CMD.exe<br>从edit里输入命令<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, Grids;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Memo1: TMemo;<br> Edit1: TEdit;<br> procedure Edit1KeyDown(Sender: TObject; var Key: Word;<br> Shift: TShiftState);<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> inputCMD:string;<br> function OutPutCmdProText(Command:string; AOutPutMemo:TMemo; ATimeOut:Cardinal=0):byte;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>function TForm1.OutPutCmdProText(Command:string; AOutPutMemo:TMemo; ATimeOut:Cardinal=0):byte;<br>var<br> hOutPutReadPipe, hOutPutWritePipe, hInPutReadPipe, hInPutWritePipe:THandle;<br> si:STARTUPINFO;<br> lsa:SECURITY_ATTRIBUTES;<br> pi
ROCESS_INFORMATION;<br> cchReadBuffer,cchWriteBuffer
WORD;<br> ph, fname
Char;<br> tk:Cardinal;<br>begin<br> inputCMD:='';<br> result:=0;<br><br> fname:=allocmem(255);<br> ph:=AllocMem(5000);<br><br> lsa.nLength :=sizeof(SECURITY_ATTRIBUTES);<br> lsa.lpSecurityDescriptor :=nil;<br> lsa.bInheritHandle :=True;<br><br> if CreatePipe(hOutPutReadPipe,hOutPutWritePipe,@lsa,0)=false then<br> begin<br> result:=1;<br> exit;<br> end;<br><br> if CreatePipe(hInPutReadPipe,hInPutWritePipe,@lsa,0)=false then<br> begin<br> result:=1;<br> exit;<br> end;<br><br> fillchar(si,sizeof(STARTUPINFO),0);<br> si.cb :=sizeof(STARTUPINFO);<br> si.dwFlags :=(STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW);<br> si.wShowWindow :=SW_HIDE;<br> si.hStdInput:=hInPutReadPipe;<br> si.hStdOutput :=hOutPutWritePipe;<br> StrPCopy(fname,Command);<br><br> if CreateProcess( nil, fname, nil, nil, true, 0, nil, nil, si, pi) = False then<br> begin<br> result:=2;<br> FreeMem(ph);<br> FreeMem(fname);<br> Exit;<br> end;<br><br><br> AOutPutMemo.Lines.Clear;<br> tk:=GetTickCount;<br> while true do<br> begin<br> application.HandleMessage;<br> if not PeekNamedPipe(hOutPutReadPipe,ph,1,@cchReadBuffer,nil,nil) then<br> break;<br> if cchReadBuffer<>0 then<br> begin<br> if ReadFile(hOutPutReadPipe,ph^,4096,cchReadBuffer,nil)=false then<br> break;<br> ph[cchReadbuffer]:=chr(0);<br> AOutPutMemo.Lines.Add(ph);<br> end<br> else if(WaitForSingleObject(pi.hProcess ,0)=WAIT_OBJECT_0) then<br> break<br> else if (ATimeOut>0) and (GetTickCount-tk>ATimeOut) then<br> begin<br> TerminateProcess(pi.hProcess, 0);<br> break;<br> end;<br> if Length(inputCMD) > 0 then<br> begin<br> WriteFile(hInPutWritePipe, inputCMD[1], Length(inputCMD), cchWriteBuffer, nil);<br> inputCMD:='';<br> end;<br> end;<br><br> ph[cchReadBuffer]:=chr(0);<br> AOutPutMemo.Lines.Add(ph);<br><br> CloseHandle(hOutPutWritePipe);<br> CloseHandle(hInPutReadPipe);<br> CloseHandle(hOutPutReadPipe);<br> CloseHandle(hInPutWritePipe);<br> CloseHandle(pi.hThread);<br> CloseHandle(pi.hProcess);<br> FreeMem(ph);<br> FreeMem(fname);<br>end;<br><br><br>procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;<br> Shift: TShiftState);<br>begin<br> if key=vk_return then<br> begin<br> inputCMD:=edit1.Text+#13#10;<br> edit1.Text:='';<br> end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> OutPutCmdProText('cmd.exe',memo1);<br>end;<br><br>end.