0

在 linux bash 中运行以下命令成功:

gimp --no-interface -b '(python-fu-scale RUN-NONINTERACTIVE 0 0 "img.jpg")' -b '(gimp-quit 0)'

输出:

batch command executed successfully

被打印并且子进程退出

用 python3.5 运行它失败:

import subprocess
subprocess.run("gimp --no-interface -b '(python-fu-scale RUN-NONINTERACTIVE 0 0 \"img.jpg\")' -b '(gimp-quit 0)'".split())

结果输出:

batch command executed successfully
batch command executed successfully

并且子进程卡住了。

我不确定有什么区别以及如何在 python 中实现等效行为。有没有办法将 bash 命令作为字符串运行?

4

1 回答 1

2

使用以下来源 -在 Python 中调用外部命令 有助于找到答案

import subprocess
import shlex
subprocess.run(shlex.split("gimp --no-interface -b '(python-fu-scale RUN-NONINTERACTIVE 0 0 \"img.jpg\")' -b '(gimp-quit 0)'"))
于 2017-06-02T18:43:16.817 回答