Hi Guys
Hi Guys I am a little bit confused. I have problem with redirect stdout and stderr from python script to text file in PowerShell. I have created example code in python:
script.py
import sys
print("This is standard output")
print("This is error", file=sys.stderr)
Then I am trying to redirect output and stderr to file like this:
python .\script.py *>&1 | Tee-Object -FilePath out.txt
I am getting all the time error that is not expected. After execute above command I should receive out.txt with two line text. First line: “This is standard output” and second line: “This is error”.
Unfortunately I received below output:
This is standard output
python : This is error
At line:1 char:1
+ python .\test_script.py *>&1 | Tee-Object -FilePath wyjscie.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (This is error:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Can someone point what is wrong with above redirection or generally what I am doing wrong? Using 2>&1 redirection also cause the same error.
Expected output (like in linux systemm using tee command and 2>&1):
This is standard output
This is error