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