subprocess() arguments in Python
I have an argument in Python that is screwing up my subprocess() command. The argument is:
--server-args="-screen 0, 1280x800x24"
args = [
'xvfb-run',
'--server-args="-screen 0, 1280x800x24"',
'/usr/bin/python',
'/root/AdamN-python-webkit2png-3ae4322/webkit2png.py',
'-o',
filename,
url,
]
I think it's escaping the double quotes.开发者_StackOverflow Is there a work around for this?
While you've probably figured this out in the past two years, I had this same problem today. The solution:
import subprocess
subprocess.check_call(['xvfb-run', '-s', '-screen 0 1024x768x24',
'CutyCapt',
'--url=http://www.google.com/',
'--out=google.png'])
or
import subprocess
subprocess.check_call(['xvfb-run', '--server-args=-screen 0 1024x768x24',
'CutyCapt',
'--url=http://www.google.com/',
'--out=google4.png'])
Assuming you have xvfb installed. I am using CutyCapt as my sample application that requires an X framebuffer to run (its a program that converts webkit pages to images and requires an X server).
This is Python code, not a shell command line.
A shell command line eats the quotes to keep the spaces - in Python, the spaces are kept by a different means, so the quotes are passed on as-is and become part of the argument the called program actually sees.
精彩评论