-5

I want to know how to open the Linux Terminal in a Java app.

Further explanation: I have a java app. There is a button inside my java app. When you click that button, the Linux Terminal must pop open. I won't run or do anything on the Terminal, I just want to open it.

I've been searching for few hours but found none that suites what I want to do.

Please write the code itself and don't answer by giving links like "this may help".

JJC
  • 493
  • 1
  • 6
  • 10
  • Can we see your code please? – Juned Ahsan Jul 25 '13 at 06:19
  • 1
    This question appears to be off-topic because Stack Overflow is about helping with specific programming issues. It is not a place that provides 'Code-on-demand.' – Jeremy J Starcher Jul 25 '13 at 06:33
  • @JeremyJStarcher.. I'm asking how to open the terminal in java so obviously codes are the answer – JJC Jul 25 '13 at 07:38
  • @JunedAhsan.. As I mentioned, I haven't found the right codes to open the terminal so no codes yet. As for the java, I can't disclose the java codes so you can imagine the codes of a button with an action listener. – JJC Jul 25 '13 at 07:39

2 Answers2

3

you can do something like this:

try {
Runtime r = Runtime.getRuntime();
String myScript = .....
String[] cmdArray = {"xterm", "-e", myScript + " ; le_exec"};
r.exec(cmdArray).waitFor();
} catch (InterruptedException ex){
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
Shuhail Kadavath
  • 448
  • 3
  • 13
1

I got the answer from the post

import java.io.*;

class TerminalLauncher
{
    public static void main(String args[]) throws IOException
    {
        String command= "/usr/bin/xterm"; 
        Runtime rt = Runtime.getRuntime();  
        Process pr = rt.exec(command);
    }
}

Hope this helps

Community
  • 1
  • 1
Sam
  • 1,298
  • 6
  • 30
  • 65