Spaces in path name
Tim Golden
mail at timgolden.me.uk
Fri Mar 14 08:03:56 EDT 2008
David S wrote:
> Gets me further but still seems to be issue with space after 'Program' as
> code tries to run 'C:\Program'. Don't understand what is going on here...
Slight apologies as I haven't followed this thread closely, but using
the Acrobat Reader executable, which is, I think, good enough for the
purposes of illustration:
<code>
import os
import subprocess
filename = r"C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe"
doc = r"C:\Program Files\Adobe\Reader 8.0\Resource\ENUtxt.pdf"
print os.path.isfile (filename)
os.system (filename + " " + doc)
os.system ('"%s" "%s"' % (filename, doc))
subprocess.call ([filename, doc])
</code>
os.path.isfile succeeds
os.system (filename) fails as your code does
os.system ('"%s"' ...) fails even though both strings are requoted
subprocess.call (filename) succeeds
The latter, at least, is because the subprocess module
has some special-case handling for exactly this situation
on MS Windows, while os.system doesn't.
Now, ultimately, I don't know if this really helps your
exact situation but it least it should be clear what will
and what won't work. Conclusion: use subprocess.call if
you can.
TJG
More information about the Python-list
mailing list