Reputation: 831
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
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
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