![](/img/trans.png)
[英]GIMP on Windows - executing a python-fu script from the command line
[英]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")
一些警告
例如subprocess.call(["gimp-console","-idf","--batch-interpreter","python-fu-eval" and so on)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.