【发布时间】:2017-07-28 08:30:56
【问题描述】:
我正在尝试使用 python subprocess 模块运行 pdftotext。
import subprocess
pdf = r"path\to\file.pdf"
txt = r"path\to\out.txt"
pdftotext = r"path\to\pdftotext.exe"
cmd = [pdftotext, pdf, txt, '-enc UTF-8']
response = subprocess.check_output(cmd,
shell=True,
stderr=subprocess.STDOUT)
TB
CalledProcessError: Command '['path\\to\\pdftotext.exe',
'path\\to\\file.pdf', 'path\\to\\out.txt', '-enc UTF-8']'
returned non-zero exit status 99
当我从 cmd 中删除最后一个参数“-enc UTF-8”时,它在 python 中工作正常。
当我在cmd 中运行pdftotext pdf txt -enc UTF-8 时,它工作正常。
我错过了什么?
谢谢。
【问题讨论】:
-
相信你需要
[pdftotext, pdf, txt, '-enc', 'UTF-8'] -
我试过了,但它可以工作,但编码不起作用。它给出了 ANSI 编码的文件。
-
我明白了....将命令作为字符串传递?
-
我将所有内容都移到了单个文件夹中,然后
cmd = r"pdftotext file.pdf demo.txt -enc UTF-8"完美运行。所以问题在于cmd格式。
标签: python python-3.x subprocess pdftotext