I need to execute the "time" command in command prompt using java. The problem with it is that after displaying the time, it asks for a new time to be set. I can execute commands like "dir" or "cd" or "ver" normally. But those commands which ask for an input from the user like "date" or "time" are not able to execute completely. Here is the code:
try {
Process p = Runtime.getRuntime().exec("cmd /c time");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
}
} catch (IOException e1) {} catch (InterruptedException e2) {}
I suspect that since the cmd is asking for an input, hence it cannot be read by the InputStream because it thinks that stream has not ended yet, and thus the program never stops executing. So, what i am looking for is a way to enter the new time when it asks me to and then print the output of that if there is any.