forked from microsoft/azure-pipelines-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessUtil.cs
38 lines (33 loc) · 1.03 KB
/
ProcessUtil.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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BuildConfigGen
{
internal static class ProcessUtil
{
public static int RunCommandWithExitCode(string program, string args, string workingDir, out string[] output)
{
using (Process p = new Process())
{
p.StartInfo.FileName = program;
p.StartInfo.Arguments = args;
p.StartInfo.UseShellExecute = false;
p.StartInfo.WorkingDirectory = workingDir;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
List<string> sb = new();
string? line;
while ((line = p.StandardOutput.ReadLine()) != null)
{
sb.Add(line);
}
output = sb.ToArray();
p.WaitForExit();
return p.ExitCode;
}
}
}
}