[Python-au] python library to discover file associations

Mike Dewhirst miked at dewhirst.com.au
Tue Feb 22 02:36:21 UTC 2011


Thanks Eric, Warwick

Here is my code ...

         if obj.main():
             cmd = '%s' % obj.logname
             subprocess.Popen(cmd, shell=True).wait()

... which now works without error unless obj.logname has a non-specific 
filename extension. At that point I get ...

   File "subprocess.pyo", line 486, in call
   File "subprocess.pyo", line 672, in __init__
   File "subprocess.pyo", line 882, in _execute_child
WindowsError: [Error 193] %1 is not a valid Win32 application

I think I'll put that in a try block and if I detect any such OSError 
I'll take a stab with Notepad on Windows or Nano on Linux.

What should I try for on Mac?

Thanks again

Mike


On 22/02/2011 9:44am, Warwick Prince wrote:
> 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
> <mailto: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 <http://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
>     <mailto: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
>         <mailto:python-au at starship.python.net>
>         http://starship.python.net/mailman/listinfo/python-au
>
>
>
>     _______________________________________________
>     python-au maillist  - python-au at starship.python.net
>     <mailto:python-au at starship.python.net>
>     http://starship.python.net/mailman/listinfo/python-au
>
>




More information about the python-au mailing list