繁体   English   中英

如何从Python脚本启动GIMP命令行?

[英]How can i launch the GIMP command line from a Python script?

从以下stackoverflow线程https://stackoverflow.com/questions/4443...mmand-line中 ,我提取了以下命令行:

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

效果很好。

现在,我想从Python脚本运行此命令,通常我使用subprocess.Popen但是这次它不起作用,我得到以下消息:

"batch command experienced an execution error"

如何从Python脚本启动GIMP命令行?

解决此问题的一种简单方法是将GIMP启动脚本放入bash脚本中,例如startgimp.sh

#!/bin/bash
#set your path to GIMP or cd into the folder where you installed GIMP
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)"

然后从Python像这样简单地调用bash脚本

import subprocess
subprocess.call(["bash","/path/to/your/script/startgimp.sh"])

如果您能够将.sh脚本设为可执行文件,例如chmod +x startgimp.sh则可以跳过bash部分并执行chmod +x startgimp.sh subprocess.call("/path/to/your/script/startgimp.sh")

一些警告

  • 这是假设您使用的是基于UNIX的系统
  • 我使用了subprocess.call,所以在等待GIMP完成时会阻塞。 如果不想使用Popen,请像以前一样使用
  • 我没有GIMP可以尝试此操作,但是您也可以尝试将GIMP命令拆分为列表中的元素,然后将其传递给子进程,看看是否可行。

例如subprocess.call(["gimp-console","-idf","--batch-interpreter","python-fu-eval" and so on)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM