[Tutor] How to pass a python variable to subprocess.call?
bill at celestial.net
Tue Oct 26 00:08:32 CEST 2010
On Mon, Oct 25, 2010, Sean Carolan wrote:
>I'm rewriting a bunch of my bash scripts to get some python practice.
>There are some instances where python doesn't have the built-in text
>processing that I need, so I'm using subprocess.call. How can I pass
>a python variable to these subprocesses? For example:
>mydir = "/usr/local/bin"
>subprocess.call("ls -l /usr/local/bin", shell=True)
>How do I replace /usr/local/bin in the subprocess call with the mydir variable?
subprocess.call("ls -l '%s'" % mydir, shell=True)
INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
Voice: (206) 236-1676 Mercer Island, WA 98040-0820
Fax: (206) 232-9186 Skype: jwccsllc (206) 855-5792
Whatever the State saith is a lie; whatever it hath is a theft.
More information about the Tutor