Where is Word?

Guy Lateur guy.lateur at b-b.be
Thu Jun 16 16:38:58 CEST 2005


Ok, I've tried various proposed solutions, and this is what I've come up 
with:

<code>
# get Word path
wordKey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, 
'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths', 0, win32con.KEY_READ)
wPath = win32api.RegQueryValue(wordKey, 'winword.exe')
win32api.RegCloseKey(wordKey)

# open/write tempfile & delete afterwards
fD, fN = tempfile.mkstemp('.txt')
fH = os.fdopen(fD, 'w')
fH.write('blabla')
fH.close()
os.spawnl(os.P_WAIT, wPath, 'winword.exe', fN)
os.remove(fN)
</code>


The above seems to work ok, but if you run the script a second time without 
first closing Word(1), the os.spawnl() doesn't seem to block. As a 
consequence, the tempfile is not removed (because Word still has it open 
when os.remove(fN) is called).

Is this behaviour normal? Anything I can do about this?

Thanks,
g





More information about the Python-list mailing list