Search code examples
pythongimppython-fu

Running python GIMP


I have a script blackandwhite.py placed in "C:\Users\Marcin.gimp-2.8\plug-ins" folder. It takes two directories as arguments. It works perfectly fine when executed from GIMP menu or from python-fu console by:

pdb.python_fu_black_and_white("L:\PICS", "L:\OUT");

However, when I try to execute it from command line by

gimp-console-2.8.exe -df --batch-interpreter python-fu-eval -b "from gimpfu import *;pdb.python_fu_black_and_white(0,"L:\PICS", "L:\OUT")" -b "pdb.gimp_quit(1)"

It gives "batch command experienced an execution error". Does anybody know how to do it properly?


Solution

  • In Windows, the simplest way is to enclose the CMD.EXE token in double quotes, and use single quotes for the Python code(*):

    gimp-console-2.8.exe -df --batch-interpreter python-fu-eval -b "from gimpfu import *;pdb.python_fu_black_and_white(0,'L:/PICS', 'L:/OUT')" -b "pdb.gimp_quit(1)"
    

    You can avoid plenty of problems by using forward slashes as file separators, Windows accepts them everywhere except in command line parameters (but here they are in Python strings).

    Also, you don't need to register your script as a plugin if you use it only in batch. See here for some sample code.

    (*) In Linux/macOS, do the opposite: single quotes around command line parms, double quotes for Python strings.