Autor Beitrag
overmoon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 16



BeitragVerfasst: Mo 03.02.03 22:51 
Ich suche nach einer Möglichkeit die Ausgabe eines Dos-Programms zu erhalten.

Ich möchte nämlich im Hintergrund eines Delphi-Programms ein altes Dos-Programm aufrufen (z.B. per ShellExecute ?). Dieses Dos-Programm hat einige Textausgaben. Und diese würde ich gerne im Delphi-Programm anzeigen.

Kennt da vielleicht jemand eine Möglichkeit ? *hoff*
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 03.02.03 23:43 
Eine Möglichkeit wären Pipes. Habe ich aber auch noch nie gemacht. Oder man macht es so:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
function TForm1.RunCaptured(const _dirName, _exeName, _cmdLine: string): String;
var 
  start: TStartupInfo; 
  procInfo: TProcessInformation; 
  tmpName: string;
  tmp: Windows.THandle;
  tmpSec: TSecurityAttributes; 
  res: TStringList; 
  return: Cardinal; 
begin
  try
    tmpName := 'Test.tmp';
    FillChar(tmpSec, SizeOf(tmpSec), #0);
    tmpSec.nLength := SizeOf(tmpSec); 
    tmpSec.bInheritHandle := True; 
    tmp := Windows.CreateFile(PChar(tmpName), 
           Generic_Write, File_Share_Write, 
           @tmpSec, Create_Always, File_Attribute_Normal, 0); 
    try 
      FillChar(start, SizeOf(start), #0); 
      start.cb          := SizeOf(start); 
      start.hStdOutput  := tmp; 
      start.dwFlags     := StartF_UseStdHandles or StartF_UseShowWindow; 
      start.wShowWindow := SW_Minimize;
      if CreateProcess(nil, PChar(_exeName + ' ' + _cmdLine), nilnil, True, 
                       0nil, PChar(_dirName), start, procInfo) then 
      begin
        SetPriorityClass(procInfo.hProcess, Idle_Priority_Class);
        WaitForSingleObject(procInfo.hProcess, Infinite);
        GetExitCodeProcess(procInfo.hProcess, return);
        CloseHandle(procInfo.hThread);
        CloseHandle(procInfo.hProcess); 
        Windows.CloseHandle(tmp);
        res := TStringList.Create;
        try
          res.LoadFromFile(tmpName);
          result := res.Text;
        finally
          res.Free;
        end
        Windows.DeleteFile(PChar(tmpName)); 
      end 
      else 
      begin
        Application.MessageBox(PChar(SysErrorMessage(GetLastError())),
          'RunCaptured Error', MB_OK); 
      end
    except 
      Windows.CloseHandle(tmp);
      Windows.DeleteFile(PChar(tmpName));
      raise
    end
  finally 
  end;
end

procedure TForm1.FormCreate(Sender: TObject);
var
  sl: TStringlist;
  i: Integer;
begin
  s := Runcaptured('C:\''ipconfig.exe''/all');
  s := Trim(s);
  sl := TStringList.Create;
  try
  begin
    sl.Text := s;
    { Leerzeilen entfernen }
    for i := sl.Count-1 downto 0 do
    begin
      if sl.Strings[i] = '' then
        sl.Delete(i);
    end;
    s := sl.Text;
  end;
  finally
    sl.Free;
  end;
  ASCII2Ansi(s);
  Memo1.Text := s;
end;


Moderiert von user profile iconKlabautermann: Code- durch Delphi-Tags ersetzt.
overmoon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 16



BeitragVerfasst: Di 04.02.03 00:13 
Danke für die schnelle Antwort.

Ich werde jetzt ersteinmal versuchen den Code zu verstehen ... :D :shock: :idea:
DaFox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189



BeitragVerfasst: Di 04.02.03 00:19 
Hi.

Oder Du schaust Dir mal folgende Komponente an. Ich habe diese vor einiger Zeit auch mal benutzt und der Source (ist dabei) kam mir sehr einleuchtend vor. Allerdings weiß ich jetzt schon nicht mehr wie das gemacht ist und kann dadurch den pädagogischen Wert dieser Komponente nicht bewerten.

:arrow: maxxdelphisite.free.fr/comp.php (TDosCommand)

Gruß,
Markus