-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConsoleProcess.cs
38 lines (35 loc) · 1.34 KB
/
ConsoleProcess.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.Diagnostics;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace Commander
{
[PublicAPI]
public static class ConsoleProcess
{
[PublicAPI, NotNull]
public static Task<int> ExecuteAsync([NotNull] string fileName, [CanBeNull] string arguments = null, [CanBeNull] string workingDirectory = null, [NotNull] params IProcessMonitor[] monitors)
{
return ExecuteAsync(new ProcessStartInfo(fileName)
{
Arguments = arguments ?? string.Empty,
WorkingDirectory = workingDirectory ?? string.Empty,
}, monitors);
}
[PublicAPI, NotNull]
private static Task<int> ExecuteAsync([NotNull] ProcessStartInfo processStartInfo, [NotNull] params IProcessMonitor[] monitors)
{
if (processStartInfo == null)
throw new ArgumentNullException(nameof(processStartInfo));
if (monitors == null)
throw new ArgumentNullException(nameof(monitors));
var execution = new ProcessExecution(processStartInfo, monitors);
var task = execution.ExecuteAsync();
return task.ContinueWith(resultTask =>
{
((IDisposable)execution).Dispose();
return task.Result;
});
}
}
}