Search code examples
javalinuxshgnu-screen

Executing screen command from Java


I am using the following code to execute an SH file in Linux

Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", file.getPath() });

This code works however I can't use the screen command in the SH file when executing it from Java, I get this error

Must be connected to a terminal.

So is it possible to "connect" java to a terminal? I would like to be able to also view this screen when I connect via SSH so I think it has to be connected to the terminal that is shown when you SSH into the server.


Solution

  • I found that if I use screen -dm it will work. Thanks!