I need to capture the output of a external process into a variable (string), so I can do some processing on that.
The answer from here works nicely as long as the process writes to stdout. However, if the process fails, it writes to stderr. I'd like to capture this string too, and I can't figure out how to do it.
Example:
$cmdOutput = (svn info) | out-string
This works, unless SVN has an error. If an error occured, SVN writes to stderr, and $cmdOutput
is empty.
How do I capture the text written to stderr in a variable in PowerShell ?
Try this:
$cmdOutput = svn info 2>&1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With