Search code examples
javalinuxcommandterminalprocessbuilder

executing commands on terminal in linux through java


I have created an standalone application in which i want that when the user clicks on the run button then the terminal should open and a particular command should be executed on the terminal. I am able to open the terminal successfully using the following code...

Process process = null;  
try {  
    process = new ProcessBuilder("xterm").start();  
} catch (IOException ex) {  
    System.err.println(ex);  
}  

The above code opens a terminal window but I am not able to execute any command on it. Can anyone tell me how to do that?


Solution

  • Suppose you are trying your gedit command then you need to provide the full qualified path to gedit (e.g /usr/bin/gedit). Similarly for all other command specify the full path.