Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell: Capture the output from external process that writes to stderr in a variable

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 ?

like image 965
driis Avatar asked Nov 18 '11 15:11

driis


1 Answers

Try this:

$cmdOutput = svn info 2>&1
like image 113
manojlds Avatar answered Sep 19 '22 02:09

manojlds