unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, AHMTCmdPipe;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    AHMCmdPipe1: TAHMCmdPipe;
    Button3: TButton;
    Label1: TLabel;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Memo2: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure AHMCmdPipe1ReceiveData(Sender: TObject; aData: String);
    procedure Button2Click(Sender: TObject);
    procedure AHMCmdPipe1Finished(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure AHMCmdPipe1ErrorData(Sender: TObject; aData: String);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Clear;
  Memo2.Clear;
  AHMCmdPipe1.Execute('cmd','c:');
end;

procedure TForm1.AHMCmdPipe1ReceiveData(Sender: TObject; aData: String);
begin
  Memo1.Lines.Text := Memo1.Lines.Text + aData;
  Application.ProcessMessages;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  AHMCmdPipe1.SendData('dir'+#13#10);
end;

procedure TForm1.AHMCmdPipe1Finished(Sender: TObject);
begin
  Label1.Caption := 'Exit Status : '+inttostr(AHMCmdPipe1.ExitCode);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  AHMCmdPipe1.SendData('exit'+#13#10);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  memo1.Clear;
  memo2.Clear;
  Memo2.Lines.Add('//AHM: DCC32 is incorrectly not writing the error output to StdError. RAD:#106861');
  AHMCmdPipe1.Execute('dcc32 Invalid.dpr',ExtractFilePath(Application.exename));
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  memo1.Clear;
  memo2.Clear;
  AHMCmdPipe1.Execute('dcc32',ExtractFilePath(Application.exename));
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  AHMCmdPipe1.SendData('some_invalid_command'+#13#10);
end;

procedure TForm1.AHMCmdPipe1ErrorData(Sender: TObject; aData: String);
begin
  Memo2.Lines.Text := Memo2.Lines.Text + aData;
  Application.ProcessMessages;
end;

end.
