Oliver
Oliver

Reputation: 831

ImageMagick Conversion from .ps to .png, run from python - invalid param

I have been looking through some similar posts and through the ImageMagick page, but I cannot seem to find a reason for my issue:

Note I am using a windows machine.

I have a .ps image in a folder and it works when running with the command to convert it from the cmd: convert saved.ps newsaved.png

However when I try to execute it from my python script with the following code:

args = ["convert","saved.ps newsave.png"] subprocess.Popen(args) #or this call(args) os.system("start newsave.png")

The cmd window says that newsave.png is an invalid parameter. (The error message being: Invalid parameter - newsave.png in the cmd window, which then closes instantly)

Having the everything seperated by a comma in args has also not helped. os.getcwd() returns the current work directory as well, so I know I'm in the right dir. The error happens when the subprocess is called.

Upvotes: 2

Views: 2491

Answers (2)

Oliver
Oliver

Reputation: 831

In the end I had to add shell=True in order for the conversion to work properly.

args = ["convert", "saved.ps", "newsave.png"] subprocess.call(args, shell=True)

Thanks to Warren for the help.

Upvotes: 0

Warren Weckesser
Warren Weckesser

Reputation: 114841

Make each command-line argument a separate element of args. Also, use subprocess.call to ensure that the convert function has completed before you call os.system("start newsave.png"):

args = ["convert", "saved.ps", "newsave.png"]
rc = subprocess.call(args)
if rc != 0:
    print "rc =", rc

Upvotes: 1

Related Questions