processLifetimeTask.TrySetException(newInvalidOperationException($"Command {filename} {arguments} returned exit code {process.ExitCode}. Standard error: \"{errorBuilder.ToString()}\""));
}
else
{
// Since the process has exited, no additional data will be written to either output buffer or error buffer, it's thread-safe to call ToString() on both outputBuilder and errorBuilder.
// NOTE: If WaitForExit() returns false, more output may be written,
// so we must synchronize access to the output StringBuilders.
WithOutputLock(
()=>
{
if(throwOnError&&process.ExitCode!=0)
{
processLifetimeTask.TrySetException(newInvalidOperationException($"Command {filename} {arguments} returned exit code {process.ExitCode}. Standard error: \"{errorBuilder.ToString()}\""));