forked from pauldotknopf/DCMTK-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.cake
53 lines (47 loc) · 1.46 KB
/
common.cake
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
//////////////////////////////////////////////////////////////////////
// HELPERS
//////////////////////////////////////////////////////////////////////
void EnsureTool(string tool, string arguements)
{
try
{
ExecuteCommand(tool + (!string.IsNullOrEmpty(arguements) ? " " + arguements : null));
Information("The tool \"" + tool + "\" is present...");
}
catch(Exception ex)
{
Error("The tool \"" + tool + "\" is not present...");
throw;
}
}
void ExecuteCommand(string command, string workingDir = null)
{
if (string.IsNullOrEmpty(workingDir))
workingDir = System.IO.Directory.GetCurrentDirectory();
System.Diagnostics.ProcessStartInfo processStartInfo;
if (IsRunningOnWindows())
{
processStartInfo = new System.Diagnostics.ProcessStartInfo
{
UseShellExecute = false,
WorkingDirectory = workingDir,
FileName = "cmd",
Arguments = "/C " + command,
};
}
else
{
processStartInfo = new System.Diagnostics.ProcessStartInfo
{
UseShellExecute = false,
WorkingDirectory = workingDir,
Arguments = command,
};
}
using (var process = System.Diagnostics.Process.Start(processStartInfo))
{
process.WaitForExit();
if (process.ExitCode != 0)
throw new Exception(string.Format("Exit code {0} from {1}", process.ExitCode, command));
}
}