从这个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命令行?
答案 0 :(得分:-1)
解决此问题的一种简单方法是将您的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部分并执行subprocess.call("/path/to/your/script/startgimp.sh")
一些警告
e.g。 subprocess.call(["gimp-console","-idf","--batch-interpreter","python-fu-eval" and so on)