运行python GIMP

运行python GIMP,python,gimp,python-fu,Python,Gimp,Python Fu,我在C:\Users\Marcin.gimp-2.8\plug-ins文件夹中放置了一个脚本blackandwhite.py。它接受两个目录作为参数。当通过以下方式从GIMP菜单或python fu控制台执行时,它工作得非常好: pdb.python_fu_black_and_white("L:\PICS", "L:\OUT"); 但是,当我试图通过命令行执行它时 gimp-console-2.8.exe -df --batch-interpreter python-fu-eval -b "f

我在C:\Users\Marcin.gimp-2.8\plug-ins文件夹中放置了一个脚本blackandwhite.py。它接受两个目录作为参数。当通过以下方式从GIMP菜单或python fu控制台执行时,它工作得非常好:

pdb.python_fu_black_and_white("L:\PICS", "L:\OUT");
但是,当我试图通过命令行执行它时

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)"
它给出了遇到执行错误的批处理命令。
有人知道如何正确执行吗?

看看您的命令在堆栈溢出时语法突出显示的方式

我会把它包起来,这样更容易看到:

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)"  #                                  ^         ^
                           #                                 here and here
你在嵌套双引号。您需要对其进行转义,或者最好用单引号替换一组:

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

在Windows中,最简单的方法是将CMD.EXE标记用双引号括起来,并对Python代码*使用单引号:

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)"
使用前向斜杠作为文件分隔符可以避免很多问题,Windows在任何地方都接受前向斜杠,除了在命令行参数中,但在这里它们是在Python字符串中

此外,如果只批量使用脚本,则不需要将其注册为插件。有关示例代码,请参见

*在Linux/macOS中,执行相反的操作:在命令行参数周围使用单引号,在Python字符串中使用双引号