|
3 | 3 | interface |
4 | 4 |
|
5 | 5 | uses |
6 | | - DOSCommand, OpenToolApi.CommandMessage; |
| 6 | + DOSCommand, OpenToolApi.CommandMessage, UtilityFunctions, 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; |
18 | | - |
19 | | -function DoRunner(APath, ACommand: string): Integer; |
| 23 | +function DoRunner(APath, ACommand: string): TRunnerReturn; |
20 | 24 | var |
21 | 25 | LDosCommand: TDosCommand; |
22 | 26 | begin |
23 | | -//System.TMonitor.Enter(FMonitorLock); |
| 27 | + LDosCommand := TDosCommand.Create(nil); |
24 | 28 | 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; |
| 29 | + LDosCommand.InputToOutput := True; |
| 30 | + LDosCommand.CurrentDir := APath; |
| 31 | + LDosCommand.CommandLine := ACommand; |
| 32 | + LDosCommand.Execute; |
| 33 | + |
| 34 | + while LDosCommand.IsRunning do |
| 35 | + begin |
| 36 | + Application.ProcessMessages; |
40 | 37 | end; |
| 38 | + |
| 39 | + Result := TRunnerReturn.Create(LDosCommand.ExitCode, LDosCommand.Lines.Text); |
41 | 40 | finally |
42 | | -// System.TMonitor.Exit(FMonitorLock); |
| 41 | + LDosCommand.Free; |
43 | 42 | end; |
44 | 43 | end; |
45 | 44 |
|
46 | | -function Runner(ACommand: string): Integer; |
| 45 | +function Runner(ACommand: string): TRunnerReturn; |
47 | 46 | begin |
48 | | - Result := DoRunner('C:/', ACommand); |
| 47 | + Result := DoRunner(ExtractFilePath(ActiveProject.FileName), ACommand); |
49 | 48 | end; |
50 | 49 |
|
51 | | -function Runner(APath, ACommand: string): Integer; |
| 50 | +function Runner(APath, ACommand: string): TRunnerReturn; |
52 | 51 | begin |
53 | 52 | Result := DoRunner(APath, ACommand); |
54 | 53 | end; |
55 | 54 |
|
| 55 | +{ TRunnerReturn } |
| 56 | + |
| 57 | +constructor TRunnerReturn.Create(AExitCode: Integer; AOutput: string); |
| 58 | +begin |
| 59 | + ExitCode := AExitCode; |
| 60 | + Output := AOutput; |
| 61 | +end; |
| 62 | + |
56 | 63 | end. |
0 commit comments