-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHelper.cs
36 lines (28 loc) · 889 Bytes
/
Helper.cs
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
using System.Collections.Immutable;
using System.Diagnostics;
static class Helper
{
public static int Run(string cmd)
{
var parts = cmd.Split(' ', 2);
return Run(parts[0], parts.ElementAtOrDefault(1) ?? "");
}
public static int Run(string exe, string args)
{
return Run(exe, args, ImmutableDictionary<string, string>.Empty);
}
public static int Run(string exe, string args, IDictionary<string, string> env)
{
var startinfo = new ProcessStartInfo
{
FileName = exe,
Arguments = args
};
foreach (var (k, v) in env)
startinfo.Environment[k] = v;
using var proc = Process.Start(startinfo)!;
Console.WriteLine($"start: ({proc.Id}) {exe} {args}");
proc.WaitForExit();
return proc.ExitCode;
}
}