[英]Python and Gimp: How to properly kill the gimp process?
I'm using a python script which is invoked by the photo software gimp to convert pdf to jpg. 我正在使用python脚本,由照片软件gimp调用以将pdf转换为jpg。 So far, the script works fine, but when it is finished, a cmd window is left open by gimp saying "press any key to exit".
到目前为止,脚本工作正常,但是当它完成时,gimp会打开一个cmd窗口,说“按任意键退出”。 This cmd window is the gimp.exe process and i cannot manage to kill it with my script (i don't want to enter user input everytime i run my script).
这个cmd窗口是gimp.exe进程,我不能设法用我的脚本杀死它(我不想每次运行我的脚本时都输入用户输入)。
I tried python commands like os.system("taskkill /im gimp-2.8.exe")
and sys.exit(0)
but none of them works. 我尝试过像
os.system("taskkill /im gimp-2.8.exe")
和sys.exit(0)
这样的python命令,但它们都sys.exit(0)
。
This is my python script: 这是我的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
This is how i invoke my gimp script from windows command line: 这是我从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)"
I would have thought that gimp command gimp_quit(1)
would close the windows but it does not. 我
gimp_quit(1)
以为gimp命令gimp_quit(1)
会关闭窗口,但事实并非如此。
It seems like such a simple issue, but i've been spending hours on this so any help appreciated. 这似乎是一个简单的问题,但我已经花了好几个小时,所以任何帮助升值。 Thanks.
谢谢。
Ok, i got the solution by asking in a gimp specific forum: 好的,我通过在gimp特定论坛中提问来获得解决方案:
The extra console window was opened because i did not specify were gimp should log it's messages. 额外的控制台窗口被打开,因为我没有指定gimp应该记录它的消息。 That's why it has opened an extra console window.
这就是为什么它打开了一个额外的控制台窗口。
So the request now looks like this: 所以请求现在看起来像这样:
"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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.