[英]How to pass a string with special chars in python to os.system. (E.g. python test.py |& tee output.txt)
The command will fail as a result of char "&".该命令将因字符“&”而失败。 Eg python test.py |& tee output.txt
例如 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
. |&
不是sh
支持的语法,但bash
支持它。 This isn't an issue with "special characters", but rather an issue with the syntax supported by the shell that os.system()
runs.这不是“特殊字符”的问题,而是
os.system()
运行的 shell 支持的语法问题。 If this is the error you're getting, you could use this sh
-compatible syntax instead如果这是您遇到的错误,则可以改用此
sh
兼容语法
os.system("python test.py 2>&1 | tee output.txt")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.