-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildHelper.cs
More file actions
94 lines (85 loc) · 2.73 KB
/
Copy pathBuildHelper.cs
File metadata and controls
94 lines (85 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;
namespace DepAnalyzer
{
class BuildHelper
{
public BuildHelper(Builder bulderComponent)
{
builder = bulderComponent;
proc = null;
}
public int RunProcess(Project proj, string app)
{
return RunProcess(proj, app, null, null, true);
}
public int RunProcess(Project proj, string app, string args)
{
return RunProcess(proj, app, args, null, true);
}
public int RunProcess(Project proj, string app, string args, string workDir)
{
return RunProcess(proj, app, args, workDir, true);
}
public int RunProcess(Project proj, string app, string args, string workDir, bool redirectOutput)
{
proc = new Process()
{
EnableRaisingEvents = true,
StartInfo = new ProcessStartInfo(app, args)
{
WorkingDirectory = workDir,
RedirectStandardOutput = redirectOutput,
RedirectStandardError = redirectOutput,
UseShellExecute = !redirectOutput,
CreateNoWindow = true,
}
};
string debugString = (workDir ?? String.Empty) + ">" + app + " " + (args ?? String.Empty);
builder.AppendLog(debugString);
proc.EnableRaisingEvents = true;
if (redirectOutput)
{
proc.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e)
{
if (proj != null)
proj.AppendLog(e.Data);
else
builder.AppendLog(e.Data);
};
}
proc.Start();
if (redirectOutput)
proc.BeginOutputReadLine();
proc.WaitForExit();
int retCode = proc.ExitCode;
if (redirectOutput && retCode != 0)
{
string error = proc.StandardError.ReadToEnd();
if (!String.IsNullOrEmpty(error))
builder.AppendLog("Error: " + error);
}
proc.Dispose();
proc = null;
return retCode;
}
public void AbortProcess()
{
if (proc != null)
{
if (!proc.HasExited)
proc.Kill();
proc.Dispose();
proc = null;
}
}
private Builder builder;
private Process proc;
}
}