The command will fail as a result of char "&". Eg python test.py |& tee output.txt
On my system, using |&
gives me this error message
sh: -c: line 0: syntax error near unexpected token `&'
|&
is not a syntax supported by sh
, but it is supported by bash
. This isn't an issue with "special characters", but rather an issue with the syntax supported by the shell that os.system()
runs. If this is the error you're getting, you could use this sh
-compatible syntax instead
os.system("python test.py 2>&1 | tee output.txt")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.