Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can i launch a gimp command line from a python script ?
#1
Hello,


From this stackoverflow thread https://stackoverflow.com/questions/4443...mmand-line , i extract this command line:

Code:
gimp-console -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import batch;batch.run('./images')" -b "pdb.gimp_quit(1)"

It worls perfectly well.

Now, i would like to run this command from a python script, usually i use subprocess.Popen....but it does not work and i get this message:
"batch command experienced an execution error"


How can i launch the gimp command line from a python script ?
Thanks
Reply
#2
Better give some extract of your Python code that includes  the Popen call as well as the exact error. I would expect something like:
Code:
Popen(["/path/to/gimp.exe","-idf","--batch-interpreter","python-fu-eval","-b","import sys;sys.path=['.']+sys.path;import batch;batch.run('./images')","-b","pdb.gimp_quit(1)"])
  • If you are using "shell=true" in the hope of making your life easier, don't, it won't.
  • Note the use of double quotes in the strings, keeping the single quotes for the Python code inside the strings (in the difficult cases, you can also use "raw" strings: r'..' or '''...''')
  • Windows accepts "/" as file separators. The only place where it doesn't is the command prompt.
Reply
#3
Hi Ofnuts,
Thank you for you feedback,

I take into account your remarks, here is the code genereating the error:

gimpPipe = subprocess.Popen( ["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 batch;batch.run('./images')", '-b', "pdb.gimp_quit(1)"], shell=False )
gimpPipe.wait()

To better understand, i simplify the command :

gimpPipe = subprocess.Popen( ["C:/Program Files/GIMP 2/bin/gimp-console-2.8.exe", '-idf', '--batch-interpreter', 'python-fu-eval','-b', "import sys;sys.path=['.']+sys.path;", '-b', "pdb.gimp_quit(1)"], shell=False )

and there is no error
So, the error is coming from the adjunction of:
-b', "import batch;",

maybe a question of path
Reply
#4
Do you have a valid batch.py file in your current directory? The basic idea is that "import sys;sys.path=['.']+sys.path;" adds a directory to the Python path (here it's '.', so that's the current directory when the command is issued, but it could be '/path/to/the/script/directory') while 'import batch' imports batch.py from that directory, and 'batch.run()' calls the run() function in it.

PS; Please take the habit to copy the error message when you report an error... I can't read it over your shoulder.
Reply
#5
(09-18-2017, 08:19 PM)Ofnuts Wrote: Do you have a valid batch.py file in your current directory? The basic idea is that "import sys;sys.path=['.']+sys.path;" adds a directory to the Python path (here it's '.', so that's the current directory when the command is issued, but it could be '/path/to/the/script/directory') while 'import batch' imports batch.py from that directory, and 'batch.run()' calls the run() function in it.

PS; Please take the habit to copy the error message when you report an error... I can't read it over your shoulder.

@ofnuts, Thank so much, it works:
I am now able to apply a  gimp filter to all files in a directory

Big Grin
Reply


Forum Jump: