• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Launching file under Linux/Unix?

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 28401
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic