簡體   English   中英

如何將 python 中帶有特殊字符的字符串傳遞給 os.system。 (例如 python test.py |& tee output.txt)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM