Although I put a correct date, if I where to put something else and it be an error. I want to know how can I write multiple inputs to the command prompt.
For example, I put "05-13-2018"
as the variable for writer.write()
. Is there any way underneath that code to enter a value if I wanted too and then have that execute. Please message me, if you don't understand what I am trying to achieve. Thanks again for all your help
import java.io.*;
import java.util.ArrayList;
public class command{
public static void main(String[] args) {
String command="cmd /c date";
try {
Process process = Runtime.getRuntime().exec(command);
OutputStreamWriter outputt = new OutputStreamWriter(process.getOutputStream());
BufferedWriter writer = new BufferedWriter(outputt);
writer.write("05-13-2018");
writer.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}