os.popen3 with windows; help?

Russell E. Owen rowen at cesmail.net
Wed Oct 27 19:27:07 CEST 2004

In article <cllv09$kv9$1 at news.Stanford.EDU>,
 "Patrick L. Nolan" <pln at cosmic.stanford.edu> wrote:

>Lad <export at hope.cz> wrote:
>> "Russell E. Owen" <rowen at cesmail.net> wrote in message 
>> news:<rowen-1B99F3.15314025102004 at gnus01.u.washington.edu>...
>>> I'm trying to launch an application from Python 2.3 on Windows. The 
>>> application is "ds9" (an image viewer), and is installed in C:\Program 
>>> Files\ds9\ds9
>> I think the problem is in long name folder: Program Files. So, try
>> Progra~1 instead of Program Files
>An automatic way to accomplish this is
>import win32api
>shortpath = win32api.GetShortPathName(path)
>Also, I have found by bitter experience that ds9 is unable to open any
>file whose path includes a space.  Put your data files somewhere else.

Thanks to everyone for their replies.

Lad and Patrick's suggestions both worked perfectly. (Simply trying to 
protect the path with an extra set of quotes, as suggested by one kind 
non-Windows-savvy soul, did not work)..

I also tested the bug mentioned by Patrick. I put a fits image file into 
a directory whose name contained a space and tried to open that file in 
ds9. it worked fine. I hope this means that the problem with spaces in 
names has been thoroughly fixed.

Tip for ds9 and xpa users (xpa is a communication protocol used by ds9):
I learned from a ds9 developer that a proper installation of ds9 and 
should have the xpa files in the same directory as ds9. This is NOT how 
the binary ds9 and xpa installers do it, but it is easy to fix after the 
installation. Unless this is done, ds9 cannot register itself with xpa, 
making communication needlessly messy.

One more question:
- I noticed that when I use os.popen3 to open ds9, i have to keep the 
returned reference to stdout around as long as ds9 itself is open or 
Python hangs. I can't close it. I can't lose the reference and allow it 
to be garbage-collected. Any suggestions for avoiding this? (At least it 
doesn't prevent Python from shutting down when requested.)

I had been using os.spawn... to launch ds9, but spawn is not supported 
on Windows, alas. I communicate with ds9 via xpa, so the pipes returned 
by popen3 are of no interest.

-- Russell

More information about the Python-list mailing list