Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Delphi 5] Dosapplikation->Rückgabewert in Pipe umleiten

Empfohlene Antworten

Veröffentlicht

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.