Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have made a Java program that could open any application. Suppose there is a file name "*.jpg", the it would allow the OS to recognize the type of application and then open the default application. Another example: Suppose the file's name is "*.flv", then it would open up the default media player just like when you click an icon in nautilus but the only difference was that it was in command line. Here is the java program for that:

import java.awt.*;
import java.io.*;
public class OpenFile{
    public static void main(String args[]){
      try{
          String filename = args[0];
          System.out.println(args[0]);
          Desktop.getDesktop().open(new File(filename));
      }
      catch(Exception e){
          System.out.println("Sorry an exception occured. Could not perform the operation.");
      }
    }
 }

Now this script leads to performance issues. Now I want to write a BASH script to do this task ??

share|improve this question
    
so what is your question? –  MattDMo Apr 4 '13 at 15:29
    
@MattDMo sorry! forgot to put that! Now I have edited the post. –  Pranit Bauva Apr 4 '13 at 15:31
add comment

1 Answer 1

up vote 10 down vote accepted

There is already an external command for this. There is nothing new that needs to be written. The command is xdg-open. It will open a file based on it's MIME type association. Here is an example:

xdg-open file.png
share|improve this answer
1  
oh! thanks! It works fine for me! Pretty good actually. –  Pranit Bauva Apr 4 '13 at 15:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.