0

I'm using Ubuntu and I just want to open the terminal from Java and execute this command make iris sim. After that keep the terminal open until the user click any key.

This is my code, but it's not working correctly:

String []commands= {"make", "iris", "sim"};
String[] cmdArray = {"/usr/bin/xterm", "-e"};
Process p = Runtime.getRuntime().exec(cmdArray, commands);
8
  • What means "it's not working correctly"? Commented May 17, 2014 at 21:59
  • its not executed and no errors.. Commented May 17, 2014 at 22:02
  • Is there a way to accomplish what you want using a shell script instead of Java? Commented May 17, 2014 at 22:04
  • That is only small part of my project, since all the project is being built by using Java. Commented May 17, 2014 at 22:08
  • stackoverflow.com/questions/10665483/… Commented May 17, 2014 at 22:09

1 Answer 1

3

You are using the exec command wrong. The second parameter is not an array of "commands" but an array of environment variables. See the JavaDocs.

Instead, simply call your command:

Process p = Runtime.getRuntime().exec("/usr/bin/xterm -e make iris sim");

Note that this will create a new process. If you want to wait for this process call p.waitFor();.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, I did exactly what you said but it's also not working. Actually it works if I change the command( e.g. gedit filename.txt), but make iris sim command is not executed ...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.