On Mar 14, 8:15 pm, "David S" <[EMAIL PROTECTED]> wrote:
> By mapping network drives in windows I can get past these issues with path
> names.
>
> Thanks,
> David
>
> "Tim Golden" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
> > 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

I had the same problem recently with subprocess.popen, when there is a
space in the executable and a space in an additional argument as in
the acrobat example. I finally found a past thread in this news group
that explained that you have to use two (2) leading double quotes, and
as on the command line all arguments with spaces have to be quoted.

All three examples with acrobat work on my WindowsXP in this case
(opens Acrobat three times, after closing previous):

<code>
import os
import subprocess

filename = r"C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe"
doc = r"C:\Program Files\Adobe\Acrobat 7.0\Help\ENU\Pdfmark.pdf"

print os.path.isfile (filename)
print 'case 1'
os.system ('""' + filename + '" "' + doc + '"') # quotes split up for
clarity:  (' " " ' + filename + ' " " ' + doc + ' " ')
print 'case 2'
os.system ('""%s" "%s"' % (filename, doc))
print 'case 3'
subprocess.call ([filename, doc])

</code>

Josef
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to