I need to launch the xterm from my java application and send command to it.
This xterm needs to be opened for a while and run commands on it on-demand. Read the output from it, is another use-case.
When I check for the solution, everyone is suggesting this : [/questions/15356405/how-to-run-a-command-at-terminal-from-java-program?noredirect=1&lq=1]
But my requirement is bit different.
String[] command= {"/bin/bash", "-c", "xterm"};
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);
BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
ReadThread input = new ReadThread(in);
input.start();
PrintWriter printWriter = new PrintWriter(new BufferedWriter(new
OutputStreamWriter(pr.getOutputStream())),true);
WriteThread writeThread= new WriteThread(printWriter);
// This 'writeThread' thread send commands based on some event like below
// printWriter.println("ls -an");
Read thread actually reading from the process that launched xterm, not directly from xterm. Read message is some thing like this: “Stdout: Warning: Tried to connect to session manager, Could not open network socket”
There is another issue too.
How can I directly communicate with launched Xterm from java.
I have also tried to use ‘-into’ to add xterm to Java native window. This makes the xterm non-interactive.
6