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

谁都会走 提交于 2019-12-11 04:07:01

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/33282658/imagemagick-conversion-from-ps-to-png-run-from-python-invalid-param

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!