27 public async Task<ExternalSolverProcessResult>
RunAsync(
28 string executablePath,
29 IEnumerable<string> arguments,
30 string workingDirectory,
31 string? standardInput,
32 CancellationToken cancellationToken)
34 ArgumentException.ThrowIfNullOrWhiteSpace(
36 ArgumentNullException.ThrowIfNull(
38 ArgumentException.ThrowIfNullOrWhiteSpace(
44 FileName = executablePath,
45 WorkingDirectory = workingDirectory,
46 UseShellExecute =
false,
47 CreateNoWindow =
true,
48 RedirectStandardOutput =
true,
49 RedirectStandardError =
true,
50 RedirectStandardInput = standardInput is not
null
53 foreach (
string argument
in arguments)
55 startInfo.ArgumentList.Add(
62 StartInfo = startInfo,
63 EnableRaisingEvents =
true
68 throw new InvalidOperationException(
69 $
"Unable to start solver executable '{executablePath}'.");
75 int cancellationObserved =
78 using CancellationTokenRegistration registration =
79 cancellationToken.Register(
83 ref cancellationObserved,
91 Task<string> standardOutputTask =
92 process.StandardOutput.ReadToEndAsync();
94 Task<string> standardErrorTask =
95 process.StandardError.ReadToEndAsync();
97 if (standardInput is not
null)
99 await process.StandardInput.WriteAsync(
102 process.StandardInput.Close();
105 await process.WaitForExitAsync(
106 CancellationToken.None);
108 string standardOutput =
109 await standardOutputTask;
111 string standardError =
112 await standardErrorTask;
116 ExitCode = process.ExitCode,
117 StandardOutput = standardOutput,
118 StandardError = standardError,
120 Volatile.Read(ref cancellationObserved) != 0 ||
121 cancellationToken.IsCancellationRequested