Regarding the topic, the code below
Process proc = null;
try {
String[] cmdss= {"gnome-terminal"};
proc = Runtime.getRuntime().exec(cmdss, null, wd);
} catch (IOException e) {
e.printStackTrace();
}
Runs the terminal form Ubuntu.
How do I issue commands into the terminal after running the termnal?
eg: running the terminal and run command such as “ls” etc.
You can give
gnome-terminalsome options on the command line what it shall execute.The
-xoption gives you roughly the same benefit but you can split the commandline into separate words.Both
-eand-xrun the program with optional arguments while connecting the program`s standard input and output to the terminal. So the user can interact with the terminal properly.Example:
This will open the terminal and run the “program”
bash.bashwill get two arguments:-candls; echo ....; read. The-coption makes bash parsing and executing the next argument. This will callls, thenecho ...thenreadwhich waits for the return key.In Java you must split the arguments appropriately into an array like this: