os.popen3 with windows; help?

Patrick L. Nolan pln at cosmic.stanford.edu
Tue Oct 26 12:46:01 EDT 2004


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
>> 
>> On unix I just do:
>> os.popen3("ds9")
>> and close the returned files and all is good. (I'm not trying to 
>> communicate with the program via popen3 and so had been using 
>> os.spawnlp, but that doesn't exist on Windows.)
>> 
>> On Windows os.popen3("ds9") does nothing, and the stderr returned from 
>> os.popen3 has a message saying the program is unknown.
>> 
>> So I tried being specific:
>> os.popen3("C:\\Program Files\\ds9\\ds9")
>> This also fails and the program that is not found is "C:\Program", 
>> suggesting that the space in "Program Files" is causing the problem. The 
>> following failed in exactly the same way:
>> os.popen3("C:\\Program\ Files\\ds9\\ds9")
>> 
>> Any suggestions?
>> 
>> -- Russell
>> 
>> P.S. I installed the app using its Windows binary installer, which 
>> unpacks a few files in C:\\Program files\. Windows doesn't seem to know 
>> the program exists; it's not in the task bar, for example. But one can 
>> double-click it to run it.

> 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)
os.popen3(shortpath)

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.

-- 
*   Patrick L. Nolan                                          *
*   W. W. Hansen Experimental Physics Laboratory (HEPL)       * 
*   Stanford University                                       *



More information about the Python-list mailing list