0

I am trying to use the bash shell command "read" in java however i get an exception saying there is no such program or directory even though i can use the command directly in the shell.

This is my java method.

    public void waitForKeyPress()
{
    ArrayList<String> cmd = new ArrayList();
    cmd.add("read");
    cmd.add("-n1");
    cmd.add("-s");
    ProcessBuilder pb = new ProcessBuilder(cmd);
    pb.inheritIO();
    try {
        Process p = pb.start();
        p.waitFor();
    } catch(Exception e)
    {
        Printer.printError(pName, "Could not wait for key press.", e);
    }

}

and this is the result

This is all in effort to make a "press any key to continue" function so if a different approach exists let me know. thanks

Omar Alama
  • 29
  • 6
  • 1
    `read` is a shell builtin command, so you need to do `bash -c 'read -n1 -s'` – glenn jackman Sep 20 '17 at 21:03
  • @glennjackman your solution works there is no need for all the hassle of converting to raw input just for a "press any key to continue" there is one problem though even though i supplied it with -n1 its waiting for 2 key strokes to continue – Omar Alama Sep 20 '17 at 21:15

0 Answers0