【发布时间】:2021-11-26 10:05:26
【问题描述】:
我正在使用 python 的子进程模块在我的 windows 机器上运行以下代码。
import subprocess
args = ["abiword --to=pdf '{}'".format('test.docx')]
process = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, timeout=None)
print(process.stdout.decode())
filename = re.search('-> (.*?) using filter', process.stdout.decode())
print(filename.group(1))
但是subprocess.run 给出以下错误:
b'\'"abiword --to=pdf \'test.docx\'"\' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n'
如何解决此错误,我现在应该如何处理?
另外,在我的 Windows 机器上使用 abiword 命令是否正确?我想在不安装任何第三方软件(如 libreoffice)的情况下将我的 docx 转换为 pdf。
【问题讨论】:
-
您的机器上是否安装了
abiword,它在PATH 中是否可用?换句话说,如果您在控制台 CMD.exe 窗口中键入abiword --to-pdf test.docx会发生什么? -
是的,我已经在我的 win 机器上安装了 abiword,并且 Path 变量已更新为 .exe 文件路径“C:\Program Files (x86)\AbiWord\bin”。我在 cmd 上执行
abiword --to-pdf test.docx时没有看到任何错误,但我没有看到任何 pdf 被创建。 -
@k-j 现在是 2.9.4
-
我安装了 2.8.4,但也没有用。命令行不会生成任何 pdf。我使用了 Libreoffice,但这并不能保持表格和图像的对齐。不知道我应该使用什么其他模块。
标签: python python-3.x python-docx doc