alessmar
alessmar

Reputation: 4727

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?

Upvotes: 2

Views: 266

Answers (3)

user206545
user206545

Reputation:

Windows XP has a command shell command named convert. When I feed it your command, I get the same error message you're seeing. I suspect it is being called instead of your convert.exe.

Upvotes: 0

grieve
grieve

Reputation: 13508

Are you sure the convert.exe your script is calling is the same one you are calling from the command line. I have, out of bitter experience, always used the full path to the executable I want to call from a script, Python or otherwise.

Upvotes: 0

user297250
user297250

Reputation:

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.

Upvotes: 1

Related Questions