我使用的是一个python脚本,该脚本由照片软件gimp调用以将pdf转换为jpg。到目前为止,这个脚本运行正常,但是当它完成时,gimp会打开一个cmd窗口,告诉它“按任意键退出”。这个命令窗口是gimp.exe进程,我不能设法用我的脚本杀死它(我不想每次运行我的脚本时都输入用户输入)。
我尝试了像os.system("taskkill /im gimp-2.8.exe")和sys.exit(0)这样的python命令,但它们都不起作用。
这是我的python脚本:
import os,time,sys,glob,re
from gimpfu import *
rxcountpages = re.compile(r"/Type\s*/Page([^s]|$)", re.MULTILINE|re.DOTALL)
#Convert a single pdf file
def process(infile, outfile):
print "Processing file %s " % infile
for x in range(1,countPages(infile) + 1):
print "Test"
countStr = str(x)
pdb.file_ps_load_setargs(100, 0, 0, 0, countStr, 6, 2, 2)
image = pdb.file_ps_load(infile,infile)
drawable = pdb.gimp_image_get_active_layer(image)
print "File %s loaded OK" % infile
#outfile=os.path.join('processed',os.path.basename(infile))
#outfile=os.path.join(os.path.dirname(infile),outfile)
print outfile
filename, file_extension = os.path.splitext(outfile)
output = filename + "_" + countStr + ".jpg"
print "Saving to %s" % outfile
pdb.file_jpeg_save(image, drawable, output, output, 0.9,0,1,0,"",0,1,0,0)
print "Saved to %s" % outfile
pdb.gimp_image_delete(image)
print "---------"
def countPages(filename):
data = file(filename,"rb").read()
return len(rxcountpages.findall(data))
if __name__ == "__main__":
print "Running as __main__ with args: %s" % sys.argv下面是我从windows命令行调用gimp脚本的方式:
"C:\Program Files\GIMP 2\bin\gimp-2.8.exe" -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import PDF;PDF.process('%1','%2');PDF.exit()" -b "pdb.gimp_quit(1)"我本以为gimp命令gimp_quit(1)会关闭窗口,但它没有。
这似乎是一个简单的问题,但我已经花了几个小时在这个问题上,所以感谢任何人的帮助。谢谢。
https://stackoverflow.com/questions/44628954
复制相似问题