Spaces in path name

joep josef.pktd at gmail.com
Sun Mar 16 09:23:21 EDT 2008



Tim Golden wrote:

> subprocess.call ([
>
>    r"C:\Program Files\Adobe\Acrobat 5.0\Reader\acro reader.exe",
>
> r"C:\Program Files\Adobe\Acr
> obat 5.0\Reader\plug_ins.donotuse\Annotations\Stamps\abc def.pdf"
>
> ])
>
> Can you confirm that something equivalent *doesn't* work on your
> setup? Or have I misunderstood your point earlier? I'd really
> like to get to the point where we can definitively state: this
> works (and possibly: that doesn't).
>
> Thanks
> TJG

This works without problems for me on Windows XP, Python 2.4.3

In the past, I didn't have problems with subprocess.call, and I never
had to look closer to the different versions of quoting.

I often had problems understanding subprocess.Popen and getting it to
work. For example the equivalent case for popen, as your
subprocess.call example, does not work, or I'm making a different
mistake with subprocess.Popen:

p = subprocess.Popen([
        r"C:\Program Files\WinRAR\Rar.exe",
        r"C:\temp\Copy of papers.rar"],
                     shell=True, stdout=subprocess.PIPE)
rettext,reterror = p.communicate()
retcode = p.wait()
p.stdout.close()

results in:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

I assume that there is some difference how subprocess.call and
subprocess.Popen handle and format the command. subprocess.Popen does
the correct formatting when only one file path has spaces and requires
double quoting, but not if there are two file paths with spaces in it.

Josef





More information about the Python-list mailing list