Veröffentlicht 30. Juni 200619 j Morgen Jungs und Mädels, folgendes Problem: Habe ein kleines Delphi-Programm welches eine DOS-Applikation startet. Der Rückgabewert des Dos-Fensters soll in eine Pipe (alternativ auch in eine Text-Datei) umgeleitet werden und anschliessen in einem Memo angezeigt werden. Natürlich funzt das net. Procedure CaptureDosCmd(sCommand : string; sparameter : string; sRerouting :string; OutputMemo : Tmemo); const CaptureBuffersize =2500; var Secattrib : TSecurityAttributes; ReadPipe : THandle; WritePipe : THandle; Startup : TStartupinfo; Processinfo : TProcessinformation; CaptureBuffer : PChar; BytesRead : DWord; WaitHandle : DWord; cmdLine : string; begin captureBuffer:='!'; CmdLine := '"' + sCommand + '" ' + sParameter; if CreatePipe(ReadPipe,writepipe, @SecAttrib,0) then begin FillChar(Startup, SizeOf(Startup), #0); with Startup do begin cb := SizeOf(Startup); dwFlags := STARTF_USESHOWWINDOW; wShowWindow := SW_SHOWNORMAL; hStdOutput := WritePipe; hStdInput := ReadPipe; end; if CreateProcess(NIL, PChar(cmdline), @Secattrib, NIL, FALSE,CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL,PChar(ExtractFilePath(sCommand)), Startup, Processinfo) then begin if not Application.Terminated then begin repeat BytesRead :=0; ReadFile(ReadPipe,CaptureBuffer[0],CaptureBufferSize,BytesRead,nil); OutputMemo.Text:=OutputMemo.Text + String(CaptureBuffer); until (BytesRead < CaptureBufferSize); end; repeat WaitHandle := WaitForSingleObject(ProcessInfo.hProcess,100); Application.ProcessMessages; until (WaitHandle>WAIT_TIMEOUT) or Application.Terminated; end; CloseHandle(ReadPipe); CloseHandle(WritePipe); end end; procedure TForm1.Button1Click(Sender: TObject); var cmd : array[0..255] of char; par : array[0..255] of char; begin GetEnvironmentVariable('COMSPEC',cmd,255); par:=''; CaptureDosCMD('C:\DeVEject\DevEject.exe','-EjectDrive:F:','>C:\test.txt',memo1); end; Problem: - Die Applikation wird zwar ausgeführt, aber der Rückgabewert nicht umgeleitet. Hat jemand ne Lösung?
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.