How do redirect
Things I've looked at:
>> and 2>> only redirect to file .-RedirectStandardOutput and -RedirectStandardError only redirect to file again.| Out-File cannot redirect stderr.| Tee-Object same issue.
Joining stdout and stderr output streams works like PetSerAl commented, though the syntax is not the most intuitive.
The weirdish syntax of 2>&1 means that stderr (stream 2) is to be added into the stdout (stream 1). As this is not actually what you are after, try adapting the other example from the MS page to Powershell:
Or, you can redirect the output to one place, and the errors to another.
dir file.xxx > output.msg 2> output.err
Thus,
$ret = myCommand 2> errors.log
should send errors in a log file and non-errors in the $ret variable.
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