groffstudio

Diff
Login

Diff

Differences From Artifact [e92472a1a9]:

To Artifact [ea372bf0cc]:


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
82








83
84
85
86
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
82
83
84
85
86
87
88
89





90
91
92
93
94
95
96
97
98
99
100
101







-
+



-
+





-





-
+


+
-
+
+


-
+

-











-
-
+
+
+
+

+
+
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+




  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Process;

type

  { TBuildStatusWindow }

  TBuildStatusWindow = class(TForm)
    mBuildOutput: TMemo;
    Label1: TLabel;
  private

  public
    function BuildDocument(CommandLine: String): Boolean;
    function BuildDocument(CommandLine: String; LogFile: String): Boolean;

  end;

var
  OutputText: String;
  BuildStatusWindow: TBuildStatusWindow;

implementation

{$R *.lfm}

function TBuildStatusWindow.BuildDocument(CommandLine: String): Boolean;
function TBuildStatusWindow.BuildDocument(CommandLine: String; LogFile: String): Boolean;
var
  p: TProcess;
  n: LongInt;
  AStringList: TStringList;
  str: String;
  lh: TextFile;
begin
  p := TProcess.Create(nil);
  p.Options := p.Options + [poWaitOnExit, poUsePipes];
  p.Options := p.Options + [poUsePipes, poStderrToOutPut];

  AStringList := TStringList.Create;
{$IFDEF WINDOWS}
  p.Executable := 'cmd';
  p.Parameters.Add('/c');
{$ENDIF}
{$IFDEF UNIX}
  p.Executable := 'sh';
  p.Parameters.Add('-c');
{$ENDIF}
  p.Parameters.Add(CommandLine);
  p.Execute;

  AStringList.LoadFromStream(p.Output);
  p.Free;
  if LogFile <> '' then
  begin
    AssignFile(lh, LogFile);
    Rewrite(lh);

    while p.Running do
    begin
  mBuildOutput.Text := AStringList.Text;
  AStringList.Free;
      n := p.Output.Read(str, 2048);
      if n > 0 then
      begin
        writeln(lh, str);
      end
      else Sleep(100);
    end;

  if Length(mBuildOutput.Text) = 0 then begin
    // We don't have any output. We can close the window.
    BuildStatusWindow.Close;
    result := True
  end
  else begin
    { We might have some buffer contents left. }
    repeat
      n := p.Output.Read(str, 2048);
      if n > 0 then
      begin
        writeln(lh, str);
      end;
    until n <= 0;

    // There was some output. Chances are that warnings occurred.
    // Keep it shown.
    // TODO: This does not always work well...
    result := False
  end;
    CloseFile(lh);
  end;

  result := p.ExitStatus > 0;
  p.Free;

  { Close the status window: }
  Close;
end;

end.