I am wondering if there is a way to execute the following shell script that is waiting for user input using the java Runtime class?
#!/bin/bash echo "Please enter your name:" read name echo "Welcome $name"
I use the following java code to accomplish this task, but it just shows an empty console.
public class TestShellScript { public static void main(String[] args) { File wd = new File("/mnt/client/"); System.out.println("Working Directory: " +wd); Process proc = null; try { proc = Runtime.getRuntime().exec("sudo ./test.sh", null, wd); } catch (Exception e) { e.printStackTrace(); } }
}
The thing is, when I execute on the program, I believe that it will execute the shell script, and the shell script will wait for user input, but it just prints the current directory and then exits. Is there a way to do this, or is it not possible at all in java?
Thanks in advance
source share