[Tutor] subprocess.call list vs. str argument

Albert-Jan Roskam fomcl at yahoo.com
Wed Feb 26 09:50:52 CET 2014


Regards,

Albert-Jan



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a 

fresh water system, and public health, what have the Romans ever done for us?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--------------------------------------------
On Tue, 2/25/14, eryksun <eryksun at gmail.com> wrote:

 Subject: Re: [Tutor] subprocess.call list vs. str argument
 To: "Dave Angel" <davea at davea.name>
 Cc: tutor at python.org
 Date: Tuesday, February 25, 2014, 11:30 PM
 
 On Tue, Feb 25, 2014 at 4:54 PM, Dave
 Angel <davea at davea.name>
 wrote:
 > CreateProcess has its own design bobbles as well. For
 example,  if
 > you forget to put quotes around the program name, 
 it will
 > happily try to add ".exe" to *multiple* places in the
 hopes that
 > one of them will work.
 >
 > Adding a file c:\program.exe to a system will blow up
 lots of
 > programs that were working by mistake for years.
 
 <snip>

Yesterday evening (it was *late* so forgive me if I wrong) I realized that part of my confusion was also caused by the fact that I ran my code in Idle.
If I called subprocess.call with a list argument, it  returned code 0 (success) but the generated sphinx code was not the same as when I ran the program from the terminal. I concluded that this is some weird interaction between Idle (which may also run in a subprocess??) and my own program. I also had no problems when I ran (in the terminal): python -c "import subprocess; subprocess.call(['sphinx-apidoc'...(etc)])"

I was surprised that the list elements of the argument for subprocess.call *have to be* separate tokens, e.g. (earlier in one of Danny's replies): a token (list element) '-f -F' won't work, it has to be two separate elements/tokens: '-f', '-F'. Apparently, subprocess.call is more than just a convenience function that " ".joins the list and escapes the resulting string.

regards,
Albert-Jan






More information about the Tutor mailing list