如何将python脚本cmd输出重定向到文件?

Gar*_* GG 4 python cmd

所以我有一个python脚本输出文本到控制台,我需要记录到文件,但脚本是非常复杂的,我不编码python,所以我宁愿不改变它.

我想做这个

>python script.py arg1 arg2 ... argn > "somefile.txt"
Run Code Online (Sandbox Code Playgroud)

但它不起作用,我的猜测是python采取>"somefile.txt"作为参数..

这可以实现吗?如何实现?

cfe*_*uke 5

$ (python script.py one two) > test.txt

或者,如果要查看输出并将其写入文件:

$ python script.py one two | tee test.txt

如果仍然没有写入文件,请尝试重定向STDERR:

$ python script.py one two 2>&1 | tee test.txt