os.popen3 with windows; help?
Russell E. Owen
rowen at cesmail.net
Thu Oct 28 18:58:34 EDT 2004
In article <8249c4ac.0410281110.39d68dc2 at posting.google.com>,
cappy2112 at gmail.com (Tony C) wrote:
>Michele Petrazzo <michele.petrazzo at TOGLIunipex.it> wrote in message
>> The problem is that there are spaces into the path. Try to user
>> os.popen3('"C:\\Program\ Files\\ds9\\ds9"').
>> The better choice is:
>>
>> path_complete = os.path.join('c:\\', 'Program Files', 'ds', 'ds9')
>> os.popen3('"'+ path_complete +'"' )
>>
>> It work for me.
>>
>> Michele
>
>Try using raw strings, as I had posted in my reply.
>Then you don't have to mess with joining strings, or using double
>backslashes, or qoutes within quotes.
>
>>>os.popen3(r"C:\Program\ Files\ds9\ds9")
I find this fails the same way as not using r"..." and doubling the
backslashes. Windows thinks the path to the executable stops at the
space. (I tried os.popen3(r"C:\Program Files\ds9\ds9") and the less
likely variant os.popen3(r"C:\Program\ Files\ds9\ds9"))
More info for anyone still following this thread:
The new subprocess module has promise here as a replacement for
os.popen3, since it allows a separate executable argument. Unfortunately
my tests indicate that executable and commands-as-strings (instead of
lists) aren't compatible; I've reported this as bug 1056441
<http://sourceforge.net/tracker/index.php?func=detail&aid=1056441&group_i
d=5470&atid=105470> for anyone who wants details.
I could recode to use commands-as-lists. This works, but is a big
headache for interactive use (one of the main targets for this module).
Also, for ds9 or xpa users:
- On Windows: ds9 will not connect to xpa unless the current directory
includes xpans or xpans is already running. Yecch. I ended up using
os.chdir before spawning ds9, then changing back.
- spaces in file names ARE bad news (as somebody warned me). ds9 can
open files with spaces in their names using the File menu, but not using
xpa. If the file name has a space you are totally out of luck. If the
path has a space (but not the file name) then you can try various tricks:
- quote the path in '"..."' (single quotes on the outside; no other form
of double quoting I tried worked). Fails on Windows.
- backslash-escape the spaces. Fails on Windows, of course.
- chdir to the file's directory first, then open, then chdir back. But
you can't be in two places at once. If you use chdir to get around the
os.popen3 problem of the executable having a space in its path name then
you can't also use it to get around the other problem.
Sigh.
-- Russell
More information about the Python-list
mailing list