Why is subprocess.call command not working? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Why is subprocess.call command not working? (/thread-14202.html) |
Why is subprocess.call command not working? - zBernie - Nov-19-2018 In the code snippet below, the subprocess.call command generates the file not found error shown below. However, passing the same variable "command" to os.system works. I've read that subprocess is preferroed over os.system, so I'd like to get that working. -Thanks for file in jpgfiles: jpgfile = '"' + jpgdir + file + '"' command = "convert " + str(jpgfile) + " -font Helvetica -pointsize 60 -fill lightblue -quality 100 -gravity southeast -auto-orient -annota # Generates file not found error shown below # subprocess.call([command]) # WORKS os.system(command)
RE: Why is subprocess.call command not working? - nilamo - Nov-19-2018 For subprocess.call, the first argument is the command you're calling, with args in subsequent elements. In this case, the first element should only be "convert". Args are then passed to it, and will be escaped/quoted as needed for you. From the docs: >>> import subprocess >>> help(subprocess.call) Help on function call in module subprocess: call(*popenargs, timeout=None, **kwargs) Run command with arguments. Wait for command to complete or timeout, then return the returncode attribute. The arguments are the same as for the Popen constructor. Example: retcode = call(["ls", "-l"]) >>> RE: Why is subprocess.call command not working? - wavic - Nov-19-2018 Line 4, 3 quotes. You have to break the command by spaces. command = "convert " + str(jpgfile) + " -font Helvetica -pointsize 60 -fill lightblue -quality 100 -gravity southeast -auto-orient -annota" command = command.split() RE: Why is subprocess.call command not working? - zBernie - Nov-19-2018 (Nov-19-2018, 09:02 PM)wavic Wrote: Line 4, 3 quotes. Now I'm getting the error below. -Thanks jpgdir = "/home/bernie/CentOS Share/pics/" jpgfiles = fnmatch.filter(os.listdir(jpgdir), '*.jpg') command = "convert " + str(jpgfile) + " -font Helvetica -pointsize 60 -fill lightblue -quality 100 -gravity southeast -auto-orient -annotate +80+50 %[exif:DateTimeOriginal] " + str(jpgfile) command = command.split() subprocess.call([command])
RE: Why is subprocess.call command not working? - wavic - Nov-19-2018 command is already a list. Why do you put it in square brackets? Fix the indentation. RE: Why is subprocess.call command not working? - snippsat - Nov-19-2018 @zBernie as posted over is best to past in a list,can try with string first then need shell=True .Can make a list later,as you use 3.6 i have put in some updates. import subprocess import os jpgdir = "/home/bernie/CentOS Share/pics/" file = 'test.jpg' jpgfile = os.path.join(jpgdir, file) command = f'convert "{jpgfile}" -font Helvetica -pointsize 60 -fill lightblue -quality 100 -gravity southeast -auto-orient -annotate +80+50 %[exif:DateTimeOriginal] {jpgfile}' subprocess.run(command, shell=True)Dos not work post your original convert command before you take into Python.
|