I have the following files:
test.ps1
& e:\test.bat > stdout.txt 2> stderr.txt
test.bat
@echo off
echo write to stdout
echo write to stderr >&2
When I call test.ps1
like this:
powershell -ExecutionPolicy bypass e:\test.ps1
The output files look like this:
stdout.txt
write argument to stdout
stderr.txt
test.bat : write to stderr
At E:\test.ps1:5 char:1
+ & "$application" "$argument" > $stdout 2> $stderr
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (write to stderr :String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
There is an answer how to prevent the NativeCommandError output from being written to file when redirecting both stdout and stderr to the same file, but how can I achieve that when writing to different files?