Salut à tous, j’espère que je suis dans la bonne catégorie ^^

Actuellement j'ai une application console nommée "calc.exe" utilisable en ligne de commande, et j'essaye de créer une application visuel performante en Delphi permet d'utiliser cette application,

Je déjà créer un GUI pour cette application console de la façon suivante :
  • On utilisant ShellExecute j’exécute l'application "calc.exe" avec les paramètres nécessaires
  • Je capture le texte sortie (Output), je l'analyse, et je le traite de la façon nécessaire


Voici la fonction que j'utilise pour exécuter et capturer le output, je l'ai trouvé sur net
Code delphi : Sélectionner tout - Visualiser dans une fenêtre à part
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
function ExecCatch(App:String; ReturnOutput: Boolean): String;
const
  ReadBuffer = 2400;
var
  Security : TSecurityAttributes;
  ReadPipe,WritePipe : THandle;
  start : TStartUpInfo;
  ProcessInfo : TProcessInformation;
  Buffer : Pchar;
  BytesRead : DWord;
  Apprunning : DWord;
  Output: String;
begin
  Output := '';
  With Security do begin
    nlength := SizeOf(TSecurityAttributes) ;
    binherithandle := true;
    lpsecuritydescriptor := nil;
  end;
  if Createpipe (ReadPipe, WritePipe,
                  @Security, 0) then begin
    Buffer := AllocMem(ReadBuffer + 1) ;
    FillChar(Start,Sizeof(Start),#0) ;
    start.cb := SizeOf(start) ;
    start.hStdOutput := WritePipe;
    start.hStdInput := ReadPipe;
    start.dwFlags := STARTF_USESTDHANDLES +
                         STARTF_USESHOWWINDOW;
    start.wShowWindow := SW_HIDE;
 
    if CreateProcess(nil,
           PChar(App),
           @Security,
           @Security,
           true,
           NORMAL_PRIORITY_CLASS,
           nil,
           nil,
           start,
           ProcessInfo)
    then
    begin
     repeat
      Apprunning := WaitForSingleObject
                   (ProcessInfo.hProcess,100) ;
      Application.ProcessMessages;
     until (Apprunning <> WAIT_TIMEOUT) ;
     if ReturnOutput then
      Repeat
        Application.ProcessMessages;
        BytesRead := 0;
        ReadFile(ReadPipe,Buffer[0],
        ReadBuffer,BytesRead,nil) ;
        Buffer[BytesRead]:= #0;
        OemToAnsi(Buffer,Buffer) ;
        Output := Output + String(Buffer) ;
      until (BytesRead < ReadBuffer) ;
   end;
   FreeMem(Buffer) ;
   CloseHandle(ProcessInfo.hProcess) ;
   CloseHandle(ProcessInfo.hThread) ;
   CloseHandle(ReadPipe) ;
   CloseHandle(WritePipe) ;
   end;
   result := Output;
end;

ça prend du temps, des fois ça BUG, SVP y a-t-il une méthode plus performante (non juste la fonction de capture) ? ou un composant ? toute proposition est la bienvenue, Merci d'avance .