[SciPy-user] subprocess

Xavier Saint-Mleux saintmlx@apstat....
Tue Jun 23 16:16:43 CDT 2009


Nils Wagner wrote:
> On Tue, 23 Jun 2009 11:20:45 -0600
>  Jim Vickroy <Jim.Vickroy@noaa.gov> wrote:
>> Nils Wagner wrote:
>>> On Tue, 23 Jun 2009 10:52:13 -0600
>>>   Jim Vickroy <Jim.Vickroy@noaa.gov> wrote:
>>>  
>>>> Nils Wagner wrote:
>>>>    
>>>>> Hi all,
>>>>>
>>>>> Sorry if the subject is off-topic.
>>>>>
>>>>> How can I run gimp from python using subprocess ?
>>>>>
>>>>> I would like to use several arguments, e.g.
>>>>>
>>>>> gimp --batch-interpreter=plug-in-script-fu-eval -i -d -b
>>>>> '(script-autocrop "a.png")' -b '(gimp-quit 0)'
>>>>>
>>>>>
>>>>> Thanks in advance.
>>>>>
>>>>>                Nils
>>>>> _______________________________________________
>>>>> SciPy-user mailing list
>>>>> SciPy-user@scipy.org
>>>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>>>         
>>>> ... don't know what Python version you are using but recent
>>>> releases (version 2.4 and later) include the *subprocess* module.
>>>>
>>>> Questions of this sort are best posted to *comp.lang.python*.
>>>>     
>>>   Thank you for your response.
>>> I know how to import subprocess, but how do I deal with all the
>>> quotes in the argument list
>>> of my gimp command ?
>>>
>>> Nils
>>> _______________________________________________
>>> SciPy-user mailing list
>>> SciPy-user@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>   
>> It is usually a good idea to (at a minimum) post:
>>
>>    *  a small script that demonstrates the error
>>    * the exact text of the error the script triggers
>>    * the version of Python you are using
>>    * the OS you are using
>
> Sure, I am using openSuSe 11.1 on x86_64 GNU/Linux, python2.6.
> gimp --version
> GNU Image Manipulation Program Version 2.6.2
>
> The script script-autocrop.scm should be placed in in ~/.gimp2.6/scripts
>
> python -i autocrop.py
>
> (gimp:8196): Gimp-Core-CRITICAL **: gimp_image_opened: assertion
> `GIMP_IS_GIMP (gimp)' failed
> GIMP-Fehler: »/home/nwagner/)'« konnte nicht geöffnet werden: Datei
> oder Verzeichnis nicht gefunden
>
> batch command executed successfully
> batch command executed successfully
>
> ^CTraceback (most recent call last):
>   File "autocrop.py", line 6, in <module>
>     assert subprocess.call(cmd)==0, 'Error in cmd: %s' % cmd #
> Returncode should be zero
> gimp: terminated: Unterbrechung
>   File "/usr/lib64/python2.6/subprocess.py", line 444, in call
>     return Popen(*popenargs, **kwargs).wait()
>   File "/usr/lib64/python2.6/subprocess.py", line 1137, in wait
>     pid, sts = os.waitpid(self.pid, 0)
> KeyboardInterrupt
> /usr/lib64/gimp/2.0/plug-ins/script-fu terminated: Unterbrechung
>
>
> Datei oder Verzeichnis nicht gefunden means file or directory missing
>
> Nils

subprocess.call has shell=False by default, which means that the
parameters are not interpreted by a shell and are sent as is.  In your
case, it means that  "'(script-autocrop ", filename and ")'" are three
separate parameters instead of one; you should concatenate everything
into a single string.  Also, the single quotes are superfluous:
'(quit-gimp 0)' is a symbol, not a function call, and is always
"executed successfully."

e.g. (I have not installed your scheme script)

>>> cmd=["gimp", "--batch-interpreter=plug-in-script-fu-eval", "-i", "-d", "-b","'(gimp-quit 0)'"]
>>> assert subprocess.call(cmd)==0, 'Error in cmd: %s' % cmd # Returncode should be zero
batch command: executed successfully.


Traceback (most recent call last):
/usr/lib/gimp/2.0/plug-ins/script-fu terminated: Interrupt
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/subprocess.py", line 444, in call
gimp: terminated: Interrupt
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.5/subprocess.py", line 1178, in wait
    pid, sts = self._waitpid_no_intr(self.pid, 0)
  File "/usr/lib/python2.5/subprocess.py", line 1008, in _waitpid_no_intr
    return os.waitpid(pid, options)
KeyboardInterrupt
>>> cmd=["gimp", "--batch-interpreter=plug-in-script-fu-eval", "-i", "-d", "-b","(gimp-quit 0)"]
>>> assert subprocess.call(cmd)==0, 'Error in cmd: %s' % cmd # Returncode should be zero
>>>


Hope this helps,

Xavier

P.S. Sorry if you get this message twice; I sent it to the list but it is still not showing up after almost 3h.







More information about the SciPy-user mailing list