[英]How to pass a string with special chars in python to os.system. (E.g. python test.py |& tee output.txt)
該命令將因字符“&”而失敗。 例如 python test.py |& tee output.txt
在我的系統上,使用|&
給了我這個錯誤信息
sh: -c: line 0: syntax error near unexpected token `&'
|&
不是sh
支持的語法,但bash
支持它。 這不是“特殊字符”的問題,而是os.system()
運行的 shell 支持的語法問題。 如果這是您遇到的錯誤,則可以改用此sh
兼容語法
os.system("python test.py 2>&1 | tee output.txt")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.