[Python-au] python library to discover file associations

Warwick Prince warwickp at mushroomsys.com
Mon Feb 21 22:44:50 UTC 2011


Hi All

Try this;

import subprocess
subprocess.Popen('txtfile.txt", shell=True).wait()

This "should" open the file using the default association and then wait
(.wait) for that app to close before continuing your code  :-)

Cheers
Warwick

On 21 February 2011 22:23, Eric O'Donnell <svvampy at gmail.com> wrote:

> Hi Mike,
>
> If calling 'os.system(txtfile)' is not sufficient, in Windows you can trek
> through the registry.
>
> First HKEY_CLASSES_ROOT\.txt which points you to the 'txtfile' entry.
> Then HKEY_CLASSES_ROOT\txtfile\shell\open\command
> the value on my system is:
> %SystemRoot%\system32\NOTEPAD.EXE %1
>
> I don't know what you need to do on other platforms, perhaps look at the
> code for os.system?
>
> Hmm, I just tried that via Cygwin:
> >>> import os
> >>> os.name
> 'posix'
> >>> os.system('file.txt')
> sh: file.txt: command not found
> 32512
> >>>
>
> So maybe that's not as helpful as I thought.
>
> Cheers,
> Eric
>
> On 21 February 2011 17:31, Mike Dewhirst <miked at dewhirst.com.au> wrote:
>
>> I want to launch the system text editor with a known text file but I don't
>> know what that editor might be on which platform.
>>
>> Is there a Python library which can discover the system text editor on any
>> platform?
>>
>> TIA
>>
>> Mike
>>
>> _______________________________________________
>> python-au maillist  -  python-au at starship.python.net
>> http://starship.python.net/mailman/listinfo/python-au
>>
>
>
> _______________________________________________
> python-au maillist  -  python-au at starship.python.net
> http://starship.python.net/mailman/listinfo/python-au
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://starship.python.net/pipermail/python-au/attachments/20110222/30cf12df/attachment.htm>


More information about the python-au mailing list