This question already has answers here:
Closed 2 years ago.
How to redirect output with subprocess in Python?
(5个答案)
我正试图从这个命令获取输出:“hocr pdf”
因此,当我在命令行中运行此命令时,它运行得非常好,这就是我键入命令的方式:
为了让这个命令工作,我必须在工作目录中有2个扩展名如下的文件(jpeg,hocr)
因此,当尝试运行包含此命令的脚本时,将显示以下内容:
这是我的代码:
(5个答案)
我正试图从这个命令获取输出:“hocr pdf”
因此,当我在命令行中运行此命令时,它运行得非常好,这就是我键入命令的方式:
hocr-pdf . > converted.pdf
为了让这个命令工作,我必须在工作目录中有2个扩展名如下的文件(jpeg,hocr)
因此,当尝试运行包含此命令的脚本时,将显示以下内容:
hocr-pdf: error: unrecognized arguments: gg
这是我的代码:
from enter_filename import f2files
from f1fileOpen import f1file
from findPDF import OCRized
import subprocess
a =f1file()
if not OCRized(a):
p1=subprocess.check_call(["convert","-density","300",a,"-depth","8","converted.jpg"])
print "Conversion to jpg was successful"
p=subprocess.check_call(["tesseract","converted.jpg",'converted',"-l","eng","hocr"])
print "tesseract done the job"
p2=subprocess.check_call(["hocr-pdf",".>","gg"])
else:
p=subprocess.check_call(["tesseract",'1.png','f1',"-l","eng"])
最佳答案
在使用shell功能时,应使用以下命令调用shell:
p2=subprocess.check_call(["bash","-c","hocr-pdf .> gg"])
10-08 03:37