Spaces in path name

joep josef.pktd at gmail.com
Sun Mar 16 11:41:51 EDT 2008



Tim Golden wrote:
> Tim Golden wrote:
> > What I haven't investigated yet is whether the additional flags
> > your example is passing (shell=True etc.) cause the main Popen
> > mechanism to take a different path.
>
> Sure enough, passing shell=True -- which is probably quite
> a rare requirement -- causes the code to change the call
> from "a.exe b.doc" to '%COMSPEC% /c "a.exe" "b.doc"'.
> The quoting rules (from cmd /?) are slightly involved but
> I can't see at first why this shouldn't work. However it
> clearly doesn't so I'll try to put together either a patch
> to the subprocess code or to the docs warning of the behaviour.
>
> I think that, in general, you need to pass shell=True far less
> often that you might imagine. (Possibly only for internal
> commands like dir, copy etc.).
>
> TJG

Thanks, I didn't know it is possible to drop the shell=True. The
explanation of the subprocess model are not very clear to me and the
examples are quite incomplete. I got it to work by trial and error and
looking at the usage in different packages.

Dropping shell=True works well for my case, no error messages and it
still captures the standard output:

p = subprocess.Popen([
        r"C:\Program Files\WinRAR\Rar.exe","v",
        r"C:\temp\Copy of papers.rar"], stdout=subprocess.PIPE)

I am still looking at different versions, and the cases when it works
and when it doesn't are still confusing.

Josef



More information about the Python-list mailing list