Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Plugin from .bat
#1
Hello Folks,

I am trying to call a Python Script from a Windows batch file, but somehow I can't get it to work. All I ever got was "batch execution failed". I am certain that the problem lies within the .bat file that I use to call the script. Can someone please tell me the right syntax?

Code:
REM switch to GIMP folder
cd C:\Users\wa2378\AppData\Local\Programs\GIMP 2\bin
REM start Gimp
Start gimp-console-2.10.exe -idf --batch-interpreter=python-fu-eval -b "import sys; sys.path=[\".\"]+sys.path;import save2png;save2png.convert(\"sample.xcf\")"

I am pretty sure the problem is with the escaped quotes but I don't know how to change that and I couldn't find a working example anywhere. The example is taken from here and untouched except the modified quotes:

http://gimpchat.com/viewtopic.php?f=9&t=15024

Thanks in advance!
Reply
#2
Where have you put save2png.py ? because you're expecting the import save2png to be able to find it.

Your GIMP installation directory is somewhat unusual as well.
Reply
#3
Change your escaped quotes to single quotes. And answer Kevin's questions. But if it just to convert between file formats, ImageMagick is normally a much better option.
Reply
#4
(02-01-2022, 03:56 PM)Kevin Wrote: Where have you put save2png.py ? because you're expecting the import save2png to be able to find it.

Your GIMP installation directory is somewhat unusual as well.

save2png.py is in the same path as the .bat, because I guessed that's what sys.path=['.']+sys.path is supposed to do. To be honest I am not completely sure, what it does. I also tried to link there with sys.path.append(%~dp0) but to no avail.

It's a portable installation, therefore the strange install dir.


(02-01-2022, 04:04 PM)Ofnuts Wrote: Change your escaped quotes to single quotes. And answer Kevin's questions. But if it just to convert between file formats, ImageMagick is normally a much better option.

I thought that single quotes are not allowed in command lines, but I will try. Thanks for the input!

No, it's not just for conversion, that's just the most simple example I could find to test the call from .bat.
Reply
#5
Code:
cd C:\Users\wa2378\AppData\Local\Programs\GIMP 2\bin

set str=%~dp0
set str1=%str:\=\\%

start gimp-2.10.exe -idf --batch-interpreter python-fu-eval -b "import sys;sys.path.append('%str1%');import bilder_check_batch;bilder_check_batch.run('%str1%')" -b "pdb.gimp_quit(1)"

this is what did the job for me. 
path.append to find the module, double slashes in the directory name and the strings called with single quotes.

Thanks for your help!
Reply


Forum Jump: