os.popen3 with windows; help?

Russell E. Owen rowen at cesmail.net
Sat Oct 30 00:33:20 CEST 2004

In article <mailman.5676.1099074998.5135.python-list at python.org>,
 Josiah Carlson <jcarlson at uci.edu> wrote:

>"Russell E. Owen" <rowen at cesmail.net> wrote:
>> - quote the path in '"..."' (single quotes on the outside; no other form 
>> of double quoting I tried worked). Fails on Windows.
>Which windows?  It works for me on both 2k and XP (though I'm not
>running ds9):
>>>> os.popen3('"C:\\Program Files\\WinImage\\winimage.exe"')
>(<open file '"C:\Program Files\WinImage\winimage.exe"', mode 'w' at 
> <open file '"C:\Program Files\WinImage\winimage.exe"', mode 'r' at 
> 0x007EC2E0>,
> <open file '"C:\Program Files\WinImage\winimage.exe"', mode 'r' at 
> 0x007EC360>)

You are right!

Putting double quotes around the path to the executable works so long as 
there are no command line arguments. Unfortunately, as soon as you add 
extra words, os.popen3 acts as if the double quotes are missing and can 
no longer find the executable.

This works:
os.popen3('"C:\\Program Files\\ds9\\ds9"')

This fails on Windows -- cannot launch C:\Program -- but I tried 
equivalent code on unix and it works fine (not that one normally needs 
it on unix; executables are usually found automatically):
os.popen3('"C:\\Program Files\\ds9\\ds9" -title foo -port 0')

I see this same bug trying to use the subprocess module in Python 2.4b1 
with my Windows Python 2.3 (see PR 105470: 

My current solution is to temporarily change to the executable's 
directory, for example:
currDir = os.getcwd()
    fds = os.popen3("xpaget ds9 file myfile.fits")


Regarding my statement you quoted:
- quote the path in '"..."' (single quotes on the outside; no other form 
of double quoting I tried worked). Fails on Windows.

That was in reference to using xpa to send file names to ds9. The file 
name is sent as a command line argument, so it's a different issue than 
discussed above. For those who care, it turns out that "{...}" is the 
recommended way to send such paths to ds9. That's fine, but it also 
turns out that ds9 on Windows requires the directory separator to be /, 
not \!

For any ds9/xpa users out there, I posted a summary what I learned: 
"Tricks for Using xpa to Command ds9": 
<http://www.astro.washington.edu/rowen/ds9andxpa.html>. I'll keep this 
updated if I learn anything new. I also hope to shorten it if some of 
the ds9 bugs and quirks are fixed. I do not discuss the details of 
os.popen3 and such, just xpa/ds9 issues.

Thank you all again for all your help. I hope to have a cross-platform 
version of RO.DS9 out in the next week or so.

-- Russell

More information about the Python-list mailing list