Gimp-Forum.net
How to close gimp with batch command? - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+--- Thread: How to close gimp with batch command? (/Thread-How-to-close-gimp-with-batch-command)



How to close gimp with batch command? - flixe - 06-19-2017

I have a simple question: When i run a python script via gimp, how can i close the command line window saying "press any key to close"?

I'm calling my script like this:

"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');" -b "pdb.gimp_quit(1)"

When i run the command an extra cmd window opens, which belongs to the gimp-2.8.exe process. Now how can i close it automatically? I would have thought pdb.gimp_quit(1) would actually do exactly that but it doesn't! I have also tried gimp.quit() within my python script, but it's not working.

Can anyone explain to me what is happening and if there is any way to finally close this stupid command line window?

Thanks...


RE: How to close gimp with batch command? - Kevin - 06-19-2017

Try using the gimp-console-2.8.exe instead of gimp-2.8.exe


RE: How to close gimp with batch command? - flixe - 06-19-2017

Then it just get an error saying "python-eval.py has crashed. The plugin python-eval.py has crashed."

This is how i invoke my script:


Quote:"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)"


This is my script:


Code:
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):
        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
        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))

#Convert all files in a directory
def run(directory):
    start=time.time()
    print "Running on directory \"%s\"" % directory
    for infile in glob.glob(os.path.join(directory, '*.pdf')):
        process(infile)
    end=time.time()
    print "Finished, total processing time: %.2f seconds" % (end-start)
if __name__ == "__main__":
    print "Running as __main__ with args: %s" % sys.argv

Please help....


RE: How to close gimp with batch command? - Kevin - 06-19-2017

And what happens if you redirect standard-out and standard-err to a file:

Code:
"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>/tmp/gimp_startup.txt 2>&1



RE: How to close gimp with batch command? - flixe - 06-19-2017

(06-19-2017, 01:39 PM)Kevin Wrote: And what happens if you redirect standard-out and standard-err to a file:

Code:
"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>/tmp/gimp_startup.txt 2>&1


I tried that and this is the content of gimp_startup.txt:

Code:
Error processing line 3 of C:\Program Files\GIMP 2\Python\lib\site-packages\pygtk.pth:

 Traceback (most recent call last):
   File "C:\Program Files\GIMP 2\Python\lib\site.py", line 152, in addpackage
     exec line
   File "<string>", line 1, in <module>
 ImportError: No module named runtime

Remainder of file ignored

** (pythonw.exe:4768): WARNING **: Trying to register gtype 'GMountMountFlags' as enum when in fact it is of type 'GFlags'

** (pythonw.exe:4768): WARNING **: Trying to register gtype 'GDriveStartFlags' as enum when in fact it is of type 'GFlags'

** (pythonw.exe:4768): WARNING **: Trying to register gtype 'GSocketMsgFlags' as enum when in fact it is of type 'GFlags'

(gimp-console-2.8.exe:5244): LibGimpBase-WARNING **: gimp-console-2.8.exe: gimp_wire_read(): error
batch command executed successfully
Error processing line 3 of C:\Program Files\GIMP 2\Python\lib\site-packages\pygtk.pth:

 Traceback (most recent call last):
   File "C:\Program Files\GIMP 2\Python\lib\site.py", line 152, in addpackage
     exec line
   File "<string>", line 1, in <module>
 ImportError: No module named runtime

Remainder of file ignored
Error processing line 3 of C:\Program Files\GIMP 2\Python\lib\site-packages\pygtk.pth:

 Traceback (most recent call last):
   File "C:\Program Files\GIMP 2\Python\lib\site.py", line 152, in addpackage
     exec line
   File "<string>", line 1, in <module>
 ImportError: No module named runtime

Remainder of file ignored

However: IT WORKS! I don't really understand why but now it is not even opening the other console window, just as it should be! Thank you!


RE: How to close gimp with batch command? - Kevin - 06-19-2017

It only opens the console window because it's needing to send things to std-out and std-err, as you're now redirecting them, there's no-need to open the console window.

Note that putting print statements into python-fu code on Windows is potentially going to cause problems as they get sent to a buffer which will overflow and hang GIMP.