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 als Prozesse dos

Empfohlene Antworten

Veröffentlicht

Hi habe da ein kleines Problem. Das Programm läuft bereits im hintergrund als prozess aber wie kann ich einen dos befehl ausführen und mir das ergebnis zurück geben lassen das das z.b so aus sieht

// gesendetter befehl

ping localhost

// rückgabe an Programm

Ping test [127.0.0.1] mit 32 Bytes Daten:

Antwort von 127.0.0.1: Bytes=32 Zeit<10ms TTL=128

Antwort von 127.0.0.1: Bytes=32 Zeit<10ms TTL=128

Antwort von 127.0.0.1: Bytes=32 Zeit<10ms TTL=128

Antwort von 127.0.0.1: Bytes=32 Zeit<10ms TTL=128

Ping-Statistik für 127.0.0.1:

Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0 (0% Verlust),

Ca. Zeitangaben in Millisek.:

Minimum = 0ms, Maximum = 0ms, Mittelwert = 0ms

ich bin für jede hilfe dankbar merci im vorraus

Also aus dem Bauch heraus würde ich jetzt mal sagen:




function GetTempPath: string;

var

  TmpDir: PChar;

begin

  TmpDir := StrAlloc(MAX_PATH);

  Windows.GetTempPath(MAX_PATH, TmpDir);

  Result := string(TmpDir);

  if Result[Length(Result)] <> '\' then

    Result := Result + '\';

  StrDispose(TmpDir);

end;


procedure Ping(AHost: String);

var StartupInfo: TStartupInfo;

    ProcessInfo: TProcessInformation;

    OutFile: String;

begin

  OutFile:= GetTempPath + 'PingOut.txt';



  FillChar(StartupInfo, sizeOf(TStartupInfo), 0);

  StartupInfo.cb:= SizeOf(TStartupInfo);

  if CreateProcess(nil, PChar('Ping.exe' + ' ' +AHost + ' > ' + OutFile),

    nil, nil, False, NORMAL_PRIORITY_CLASS,

    nil, nil, StartupInfo, ProcessInfo) then

  begin

    //*** Warten bis Ping beendet ist

    Application.ProcessMessages;

    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);

    CloseHandle(ProcessInfo.hProcess);

  end;


  Memo1.LoadFromFile(OutFile);

end;


Denke jetzt mal das könnte so funktionieren.

Bei DOS Befehlen kannst du die Ausgabe irgendwohin umleiten (mit >) bzw. die Eingabe von woanders her beziehen (also nicht über die Standardeiongabe, mit <)

Ping 127.0.0.1 > c:\PingOut.txt

zeigt also nix an, sondern schreibt alles in die Datei PingOut.txt.

Das wird oben auch gemacht und diese Datei dann ausgelesen.

EDIT:

Bei der Function GetTempPath steht in den Zeilen

if Result[Length(Result)] <> '\' und der Zeile danach ein \ (Backslash) zwischen den '', aber irgendwie zeigt er das nicht an...

ak merci ich werds mal testen. Hatte schon ein anderes Beispiel das so ähnlich funktionierte nur es konnte die Befehle nicht ausführen weil das ganze als process läuft und nicht als task.

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.