[英]How to pass variable in bash command?
我正在嘗試使用 antiword 將多個 .doc 文件轉換為 .docx 格式。 如何編寫這樣的命令:
for file in os.listdir(directory):
subprocess.run("antiword file > file+'.docx'")
它顯示了這個錯誤:
[Errno 2] No such file or directory: "antiword file > file+'.docx'": "antiword file > file+'.docx'"
除了 antiword 之外,沒有其他方法可以正確讀取對我有用的 read.doc 文件。
子進程不運行 bash。 所以運行 bash 並通過 arguments 和 arguments 記住正確的引用。
subprocess.run(["bash", "-c", "antiword \"$1\" > \"$1\".docx", "_", file])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.