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
| uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
LConvEncoding,Processutils;
type
{ TForm1 }
TForm1 = class(TForm)
Bt_Go: TButton;
Bt_GoEx: TButton;
MemConsole: TMemo;
procedure Bt_GoExClick(Sender: TObject);
private
public
procedure ProcessOutput(Sender:TProcessEx; output:string);
procedure ProcessError(Sender:TProcessEx; {%H-}IsException:boolean);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Bt_GoExClick(Sender: TObject);
var Proc: TProcessEx;
begin
try
Proc := TProcessEx.Create(nil);
Proc.Executable := 'cmd.exe';
Proc.Parameters.Add('/C');
Proc.Parameters.Add('ping.exe 127.0.0.1');
Proc.OnErrorM:=@(ProcessError);
Proc.OnOutputM:=@(ProcessOutput);
Proc.Execute();
finally
Proc.Free;
end;
end;
procedure TForm1.ProcessError(Sender: TProcessEx; IsException: boolean);
begin
MemConsole.Lines.Append('Erreur ! ' + Sender.ExceptionInfo);
end;
procedure TForm1.ProcessOutput(Sender: TProcessEx; output : String);
begin
// Quand il n'y a pas de problème d'accent
// MemConsole.Lines.Append(output);
// sinon conversion de chaîne
MemConsole.Lines.Append(ConvertEncoding(output,EncodingCP850, EncodingUTF8));
end;
end. |
Partager