I had a Java program running a shell script with a Process, but for some reason when I try to run it it throws an error open terminal failed: missing or unsuitable terminal: unknown
. From other SO questions, I think this is a tmux problem, but I'm not really sure how to solve it. Here's the code calling the script:
ProcessBuilder pb = new ProcessBuilder("/Users/user/eclipse-workspace/project/start.sh");
Process p = pb.start();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
System.out.println("output: ");
String s;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
And here's the shell script:
#! /bin/sh
ssh -tt -i ~/.ssh/ssh-key.key opc@___._.___.___ tmux attach -d << END
./run.sh
END
exit 0
I have tried running the script from terminal, and it works from the terminal but it doesn't work when I run the Java program.
CodePudding user response:
The problem is that you are attaching to an interactive tmux
session, where you need to have a terminal which supports cursor movement codes etc.
The easy workaround is to not attach; just submit the command you want to run into the session.
ssh -tt -i ~/.ssh/ssh-key.key opc@___._.___.___ tmux send-keys './run' C-m
This obviously requires that whatever is running inside the remote tmux
session is in a state where you can submit a sheld command, i.e. at a shell prompt or similar. For robustness you might want to take additional measures to make sure this is always the case.