• Post Reply Bookmark Topic Watch Topic
  • New Topic

Launching file under Linux/Unix?  RSS feed

 
Max Power
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, im trying to launch a file from within my java application. under windows i just have to write the files name to the console and the right application will be opened. how can i do that under linux/unix? just writing a filename to the console does nothing :-(

any ideas?

thanks in advance!!
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On linux there are normally multiple applications you may use to open a file for most file-types.
And the system can't know in which of the 7 browsers you like to see your html-file.
Specify the application you like to use...
 
Max Power
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, but i cant do that for every file that exists....what would happen, if i open a lets say class file in a browser under linux? i have no testing env. here...

thanks
 
M Beck
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the point is, your system might have several different applications installed that are capable of opening any given file you want to open, and the Linux OS can't know which of them you'd prefer to use for opening the file in question. so for any given file, you'll always have to know (and specify) the application you want to have open it.

after all, what if it's a text file? i must have nearly a dozen text editors on my Linux machine at home; how's the OS to know which one i prefer? similarly, i have at least four or five web browsers - if i want to open a HTML file, how should the OS know which one i want to open it in? you'll have to tell it.
 
Tim Holloway
Saloon Keeper
Posts: 18789
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Windows allows you to set a "preferred" application so that when you type, for example "resume.txt" that the document will be opened in Notepad. Or, if you alter the settings, in WordPad. Or whatever.

However, Windows is much more tied to filename extensions that Unix is. In Unix, often the extension may be omitted or can be changed to something else. The most common instance of this is shell scripts, which conventionally have an extension of ".sh", but may have no extension at all if the scripter prefers to place the script in the PATH and have it run like a compiled program would.

There are some files (mime-types and "magic") that can be used to recognize the type of a file and they are used by certain apps like web browsers and GUI desktops (Gnome/KDE). However, the stock shells make no such assumptions. You can always create your own custom shell to do what you want. That's basically all Microsoft did. However, it's actually a security risk to do so, since mistyping a data file name could then potentially launch something with unknown consequences.

Probably another reason this has never been in demand in Unix is that unlike Microsoft's adoption of a document-centric world-view, in Unix, the prevailing viewpoint is that a document is something that goes into a pipeline of one or more programs and is (commonly) transformed into a new document coming out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!