-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathProcessUtils.cs
47 lines (40 loc) · 1.18 KB
/
ProcessUtils.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
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Specialized;
using System.Diagnostics;
namespace VSharp.CSharpUtils;
public static class ProcessUtils
{
public static Process StartWithLogging(this ProcessStartInfo procInfo, Action<string> printInfo, Action<string> printError)
{
procInfo.RedirectStandardError = true;
procInfo.RedirectStandardOutput = true;
procInfo.UseShellExecute = false;
var proc = new Process();
proc.StartInfo = procInfo;
proc.OutputDataReceived +=
(_, e) =>
{
var data = e.Data;
if (string.IsNullOrEmpty(data))
return;
printInfo(data);
};
proc.ErrorDataReceived +=
(_, e) =>
{
var data = e.Data;
if (string.IsNullOrEmpty(data))
return;
printError(data);
};
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
return proc;
}
public static bool IsSuccess(this Process proc)
{
Debug.Assert(proc.HasExited);
return proc.ExitCode == 0;
}
}