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