Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 497
Harshit Agarwal Avatar asked Nov 12 '10 12:11

Harshit Agarwal


1 Answers

Try

new ProcessBuilder("xterm", "-e", 
                   "/full/path/to/your/program").start()
like image 63
Kilian Foth Avatar answered Oct 05 '22 09:10

Kilian Foth