1

我正在使用由照片软件 gimp 调用的 python 脚本来将 pdf 转换为 jpg。到目前为止,脚本运行良好,但完成后,gimp 会打开一个 cmd 窗口,说“按任意键退出”。这个 cmd 窗口是 gimp.exe 进程,我无法用我的脚本杀死它(我不想每次运行我的脚本时都输入用户输入)。

我尝试了类似的python命令os.system("taskkill /im gimp-2.8.exe")sys.exit(0)但它们都不起作用。

这是我的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)会关闭窗口,但事实并非如此。

这似乎是一个简单的问题,但我已经花了几个小时在这上面,所以任何帮助表示赞赏。谢谢。

4

1 回答 1

3

好的,我通过在 gimp 特定论坛中询问得到了解决方案:

额外的控制台窗口打开了,因为我没有指定 gimp 应该记录它的消息。这就是为什么它打开了一个额外的控制台窗口。

所以请求现在看起来像这样:

"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import PDF;PDF.process('%1','%2');" -b "pdb.gimp_quit(1)" 1>c:\\temp\\gimp_startup.txt 2>&1
于 2017-06-19T14:54:01.170 回答