|
3 | 3 | interface |
4 | 4 |
|
5 | 5 | uses |
6 | | - DOSCommand, OpenToolApi.CommandMessage; |
| 6 | + DOSCommand, OpenToolApi.CommandMessage, OpenToolApi.Tools, System.Classes; |
7 | 7 |
|
8 | | -function Runner(APath, ACommand: string): Integer; overload; |
9 | | -function Runner(ACommand: string): Integer; overload; |
| 8 | +type |
| 9 | + TRunnerReturn = record |
| 10 | + ExitCode: Integer; |
| 11 | + Output: string; |
| 12 | + constructor Create(AExitCode: Integer; AOutput: string); |
| 13 | + end; |
| 14 | + |
| 15 | +function Runner(APath, ACommand: string): TRunnerReturn; overload; |
| 16 | +function Runner(ACommand: string): TRunnerReturn; overload; |
10 | 17 |
|
11 | 18 | implementation |
12 | 19 |
|
13 | 20 | uses |
14 | 21 | System.SysUtils, Vcl.Forms; |
15 | 22 |
|
16 | | -var |
17 | | - FMonitorLock: TObject; |
| 23 | +procedure OnReadLine(ASender: TObject; const ANewLine: string; AOutputType: TOutputType); |
| 24 | +begin |
| 25 | + TCommandMessage.GetInstance.WriteLn(ANewLine); |
| 26 | +end; |
18 | 27 |
|
19 | | -function DoRunner(APath, ACommand: string): Integer; |
| 28 | +function DoRunner(APath, ACommand: string): TRunnerReturn; |
20 | 29 | var |
21 | 30 | LDosCommand: TDosCommand; |
22 | 31 | begin |
23 | | -//System.TMonitor.Enter(FMonitorLock); |
| 32 | + LDosCommand := TDosCommand.Create(nil); |
24 | 33 | try |
25 | | - LDosCommand := TDosCommand.Create(nil); |
26 | | - try |
27 | | -// LDosCommand.InputToOutput := False; |
28 | | - LDosCommand.CurrentDir := APath; |
29 | | - LDosCommand.CommandLine := ACommand; |
30 | | - LDosCommand.Execute; |
31 | | - |
32 | | - while LDosCommand.IsRunning do |
33 | | - begin |
34 | | - Application.ProcessMessages; |
35 | | - end; |
36 | | - |
37 | | - Result := LDosCommand.ExitCode; |
38 | | - finally |
39 | | - LDosCommand.Free; |
| 34 | + TCommandMessage.GetInstance.WriteLn(APath + '>' + ACommand); |
| 35 | + LDosCommand.OnNewLine := OnReadLine; |
| 36 | + LDosCommand.InputToOutput := False; |
| 37 | + LDosCommand.CurrentDir := APath; |
| 38 | + LDosCommand.CommandLine := ACommand; |
| 39 | + LDosCommand.Execute; |
| 40 | + |
| 41 | + while LDosCommand.IsRunning do |
| 42 | + begin |
| 43 | + Application.ProcessMessages; |
40 | 44 | end; |
| 45 | + |
| 46 | + Result := TRunnerReturn.Create(LDosCommand.ExitCode, LDosCommand.Lines.Text); |
41 | 47 | finally |
42 | | -// System.TMonitor.Exit(FMonitorLock); |
| 48 | + LDosCommand.Free; |
43 | 49 | end; |
44 | 50 | end; |
45 | 51 |
|
46 | | -function Runner(ACommand: string): Integer; |
| 52 | +function Runner(ACommand: string): TRunnerReturn; |
47 | 53 | begin |
48 | | - Result := DoRunner('C:/', ACommand); |
| 54 | + Result := DoRunner(ExtractFilePath(ActiveProject.FileName), ACommand); |
49 | 55 | end; |
50 | 56 |
|
51 | | -function Runner(APath, ACommand: string): Integer; |
| 57 | +function Runner(APath, ACommand: string): TRunnerReturn; |
52 | 58 | begin |
53 | 59 | Result := DoRunner(APath, ACommand); |
54 | 60 | end; |
55 | 61 |
|
| 62 | +{ TRunnerReturn } |
| 63 | + |
| 64 | +constructor TRunnerReturn.Create(AExitCode: Integer; AOutput: string); |
| 65 | +begin |
| 66 | + ExitCode := AExitCode; |
| 67 | + Output := AOutput; |
| 68 | +end; |
| 69 | + |
56 | 70 | end. |
0 commit comments