0

Running the following command in linux bash succeeds:

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

Output:

batch command executed successfully

is printed and child process exits

Running it with python3.5 fails:

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

results in output:

batch command executed successfully
batch command executed successfully

and the child process is stuck.

I'm not sure what's the difference and how to achieve equivalent behaviour in python. Is there a way to run bash command as string?

rok
  • 9,403
  • 17
  • 70
  • 126
  • Try `subprocess.run("gimp --no-interface -b".split() + ['(python-fu-scale RUN-NONINTERACTIVE 0 0 \"img.jpg\")', '-b', '(gimp-quit 0)'])` – justanothercoder Jun 02 '17 at 18:41
  • 1
    Just in case it matters, Gimp scripts only run with Python 2.7. – xenoid Jun 02 '17 at 21:13
  • thanks a lot, if i got u right. my script runs with python3, but _python-fu-scale_ runs with python 2. – rok Jun 03 '17 at 10:24

1 Answers1

2

Using the following source - Calling an external command in Python helped to find an answer

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)'"))
rok
  • 9,403
  • 17
  • 70
  • 126