source: trunk/UExternalTool.pas

Last change on this file was 1, checked in by chronos, 8 years ago
  • Imported initial version.
File size: 3.3 KB
Line 
1unit UExternalTool;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, process;
9
10var
11 ClearToolPath: string;
12 OMakePath: string;
13 SubstPath: string;
14 RationalRosePath: string;
15 SuperTracerPath: string;
16 BeyondComparePath: string;
17
18const
19 SVNPath: string = 'c:\Program Files\TortoiseSVN\bin\svn.exe';
20 SVNAdminPath: string = 'c:\Program Files\TortoiseSVN\bin\svnadmin.exe';
21
22function ExecuteProcessOut(Executable: string; Parameters: array of string;
23 CurrentDir: string = ''): string;
24function ClearTool(Parameters: array of string; CurrentDir: string = ''): string;
25procedure ExecuteNoWait(AExecutable: string; Params: array of string;
26 Maximized: Boolean = false; CurrentDir: string = '');
27function SVN(Parameters: array of string; CurrentDir: string = ''): string;
28
29
30implementation
31
32function ExecuteProcessOut(Executable: string; Parameters: array of string;
33 CurrentDir: string = ''): string;
34var
35 Process: TProcess;
36 I: Integer;
37 Cmd: string;
38 Buffer: string;
39 Count: Integer;
40begin
41 Result := '';
42 try
43 Process := TProcess.Create(nil);
44 Process.CurrentDirectory := CurrentDir;
45 Process.Executable := Executable;
46 Process.ShowWindow := swoHIDE;
47 Process.StartupOptions := [suoUseShowWindow];
48 for I := 0 to Length(Parameters) - 1 do
49 Process.Parameters.Add(Parameters[I]);
50 for I := 0 to GetEnvironmentVariableCount - 1 do
51 Process.Environment.Add(GetEnvironmentString(I));
52 Process.Options := [poUsePipes, poNoConsole];
53 Process.Parameters.LineBreak := ' ';
54 Process.Execute;
55
56 while Process.Running or (Process.Output.NumBytesAvailable > 0) or
57 (Process.Stderr.NumBytesAvailable > 0) do
58 begin
59 if Process.Output.NumBytesAvailable > 0 then begin
60 SetLength(Buffer, 1000);
61 Count := Process.Output.Read(Buffer[1], Length(Buffer));
62 SetLength(Buffer, Count);
63 Result := Result + Buffer;
64 end;
65
66 if Process.Stderr.NumBytesAvailable > 0 then begin
67 SetLength(Buffer, 1000);
68 Count := Process.Stderr.Read(Buffer[1], Length(Buffer));
69 SetLength(Buffer, Count);
70 Result := Result + Buffer;
71 end;
72 Sleep(1);
73 end;
74
75 if Process.ExitCode <> 0 then begin
76 Cmd := Process.Executable + ' ' + Process.Parameters.Text;
77 raise Exception.Create('Execution of "' + Cmd + '" failed with exit code ' + IntToStr(Process.ExitCode) + ' error: ' + Result);
78 end;
79 finally
80 Process.Free;
81 end;
82end;
83
84function ClearTool(Parameters: array of string; CurrentDir: string = ''): string;
85begin
86 Result := Trim(ExecuteProcessOut(ClearToolPath, Parameters, CurrentDir));
87end;
88
89function SVN(Parameters: array of string; CurrentDir: string = ''): string;
90begin
91 Result := Trim(ExecuteProcessOut(SVNPath, Parameters, CurrentDir));
92end;
93
94procedure ExecuteNoWait(AExecutable: string; Params: array of string;
95 Maximized: Boolean = false; CurrentDir: string = '');
96var
97 I: Integer;
98begin
99 with TProcess.Create(nil) do
100 try
101 Executable := AExecutable;
102 CurrentDirectory := CurrentDir;
103 for I := 0 to Length(Params) - 1 do
104 Parameters.Add(Params[I]);
105 if Maximized then ShowWindow := swoMaximize;
106 Options := [poNoConsole];
107 Execute;
108 finally
109 Free;
110 end;
111end;
112
113
114end.
115
Note: See TracBrowser for help on using the repository browser.