Search code examples
pythonsubprocess

Python subprocess issue on Windows


I'm trying to write a Python script to convert a bunch of images.

It's something like the following code (after a huge minimization):

#!/usr/bin/python
# -*- coding: utf-8 -*-
from subprocess import call

cmd = ' '.join(['convert.exe', '-resize', '110', 'foo\\a.jpg', 'bar\\a.jpg'])
print cmd
call(cmd)

I get the error below after executing it:

Parameter not valid - 110

While when I copy / paste the string emitted from the script on the command line the image convertion works perfectly. What did I miss?


Solution

  • I would say that the error is most likely the result of two things

    1. In the call command, try using shell=True as the second argument.
    2. You're using relative paths, and the working directory might not be the same for python as it is from your cmd shell.