Created
September 8, 2021 17:25
-
-
Save paviad/f2d635fa269561a15c05d79b46c33895 to your computer and use it in GitHub Desktop.
How to spawn a process and consume standard output and error without hanging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var process = Process.Start(processStartInfo); | |
var stdErr = process.StandardError; | |
var stdOut = process.StandardOutput; | |
var resultAwaiter = stdOut.ReadToEndAsync(); | |
var errResultAwaiter = stdErr.ReadToEndAsync(); | |
await process.WaitForExitAsync(); | |
Task.WaitAll(resultAwaiter, errResultAwaiter); | |
var result = resultAwaiter.Result; | |
var errResult = errResultAwaiter.Result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment