The canonical way to open a file with the associated program is different from one operating system (or shell) to another. Here are 4 examples that will work on the specified OSes:
Opening the File
Windows
Use the standard command shell start
, available beginning with Windows 95:
system %{cmd /c "start #{file_to_open}"}
Mac OS X
Use the standard open
command:
system %{open "#{file_to_open}"}
Linux/Unix Gnome
Use the Gnome utility gnome-open
:
system %{gnome-open "#{file_to_open}"}
Linux/Unix
Use the xdg-open
utility:
system %{xdg-open "#{file_to_open}"}
Associated Programs
Detecting the associated program for a file type can be a fairly tall order on any one system. For instance, with Windows, you have to inspect the registry, whereas with Mac OS X you have to read the right plist values; Linux is a whole other world, altogether.
You're likely better off simply requiring the user to have a program associated to make things easy enough to get started. Once you have the other logic working in your application, you might be able to add interesting features like fallback to a default application in the absence of an existing file association.
open
is a Mac convention, but Notepad is a standard windows application - on Mac, the equivalent application is TextEdit.app. – Michael Gaskill