Einzelnen Beitrag anzeigen

dominikkv

Registriert seit: 30. Sep 2006
Ort: Gundelfingen
1.109 Beiträge
 
Delphi 2007 Professional
 
#31

Re: Delphi Programm, im hintegrund cmd-befehle

  Alt 7. Dez 2007, 18:25
Zitat von DeddyH:
Wenn der Rückgabewert von ShellExecute > 32 ist, hat die Ausführung an sich funktioniert, sofern ich die Hilfe richtig lesen kann.
ja das ausführen der cmd hat ja funktioniert... was ihr wollt ist die ausgabe der cmd, nicht die ausgabe von shellexecute
du musst halt die ausgabe der cmd zu deinem programm umlenken, dann kannst du nachschauen ob das funktioniert hat.

edit:

schau dir mal das hier an:
Delphi-Quellcode:
procedure CaptureDos(command: String; Stringsp: TStrings);
const
  CaptureBufferSize = 2500;
var
  SecAttrib : TSecurityAttributes;
  ReadPipe,writePipe : THandle;
  Startup : TStartUpInfo;
  ProcessInfo : TProcessInformation;
  CaptureBuffer : Pchar;
  BytesRead : DWord;
  WaitHandle : DWord;
begin
  Stringsp.clear;
  With SecAttrib do
    begin
      nlength := SizeOf(TSecurityAttributes);
      binherithandle := true;
      lpsecuritydescriptor := nil;
    end;
  if Createpipe (ReadPipe, writePipe, @SecAttrib, 0) then
    begin
      CaptureBuffer := AllocMem(CaptureBufferSize + 1);
      FillChar(Startup,Sizeof(Startup),#0);
      Startup.cb := SizeOf(Startup);
      Startup.hStdOutput := writePipe;
      Startup.hStdInput := ReadPipe;
      Startup.dwFlags := STARTF_USESTDHANDLES +
                             STARTF_USESHOWWINDOW;
      Startup.wShowWindow := SW_HIDE;

      if CreateProcess(nil, PChar(command), @SecAttrib, @SecAttrib, true,
                       NORMAL_PRIORITY_CLASS, nil, nil, Startup, ProcessInfo) then
        begin
          repeat
            WaitHandle := WaitForSingleObject( ProcessInfo.hProcess,100);
            Application.ProcessMessages;
          until (WaitHandle <> WAIT_TIMEOUT) or application.terminated;
          if not application.terminated then
            Repeat
              BytesRead := 0;
              ReadFile(ReadPipe,CaptureBuffer[0],CaptureBufferSize,BytesRead,nil);
              CaptureBuffer[BytesRead]:= #0;
              OemToAnsi(CaptureBuffer,CaptureBuffer);
              Stringsp.Text := Stringsp.Text+String(CaptureBuffer);
            until (BytesRead < CaptureBufferSize);
        end else Stringsp.add('Fehler!');
      FreeMem(CaptureBuffer);
      CloseHandle(ProcessInfo.hProcess);
      CloseHandle(ProcessInfo.hThread);
      CloseHandle(ReadPipe);
      CloseHandle(writePipe);
    end else Stringsp.add('Konnte Dos Kommando nicht starten, Fehler: #'
                          +inttostr(getlasterror));
end;
ist aber glaub ich auch mit sichtbarem fenster
Dominik
Wer anderen eine Grube gräbt, hat ein Gruben-Grab-Gerät!
  Mit Zitat antworten Zitat