D
dream_flyer
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);<br><br> procedure RunDosInMemo(DosApp:String;AMemo:TMemo);<br> const<br> ReadBuffer = 2400;<br> var<br> Security : TSecurityAttributes;<br> ReadPipe,WritePipe : THandle;<br> start : TStartUpInfo;<br> ProcessInfo : TProcessInformation;<br> Buffer : Pchar;<br> BytesRead : DWord;<br> Apprunning : DWord;<br> begin<br> With Security do begin<br> nlength := SizeOf(TSecurityAttributes);<br> binherithandle := true;<br> lpsecuritydescriptor := nil;<br> end;<br> if Createpipe (ReadPipe, WritePipe,<br> @Security, 0) then begin<br> Buffer := AllocMem(ReadBuffer + 1);<br> FillChar(Start,Sizeof(Start),#0);<br> start.cb := SizeOf(start);<br> start.hStdOutput := WritePipe;<br> start.hStdInput := ReadPipe;<br> start.dwFlags := STARTF_USESTDHANDLES +<br> STARTF_USESHOWWINDOW;<br> start.wShowWindow := SW_HIDE;<br><br> if CreateProcess(nil,<br> PChar(DosApp),<br> @Security,<br> @Security,<br> true,<br> NORMAL_PRIORITY_CLASS,<br> nil,<br> nil,<br> start,<br> ProcessInfo)<br> then<br> begin<br> repeat<br> Apprunning := WaitForSingleObject<br> (ProcessInfo.hProcess,100);<br> Application.ProcessMessages;<br> until (Apprunning <> WAIT_TIMEOUT);<br> Repeat<br> BytesRead := 0;<br> ReadFile(ReadPipe,Buffer[0],<br> ReadBuffer,BytesRead,nil);<br> Buffer[BytesRead]:= #0;<br> OemToAnsi(Buffer,Buffer);<br> AMemo.Text := AMemo.text + String(Buffer);<br> until (BytesRead < ReadBuffer);<br> end;<br> FreeMem(Buffer);<br> CloseHandle(ProcessInfo.hProcess);<br> CloseHandle(ProcessInfo.hThread);<br> CloseHandle(ReadPipe);<br> CloseHandle(WritePipe);<br> end;<br> end;<br><br> begin {button 1 code}<br> RunDosInMemo('ping 10.43.0.1',Memo1);<br> end; <br><br>上述程序似乎只能回显ping、ipconfig等命令,我将命令参数换成<br>'d:/.../tpc.exe d:/...pas'产生问题不能回显