Answer the question
In order to leave comments, you need to log in
Java command line windows 7 how to do?
Hello everyone, I have a question, we can enter all sorts of commands into the Windows command line and they will be executed, let's say I often need to execute the same command, naturally the thought occurred to me (I myself am learning to code in Java), but is it possible to write such a program so that, when pressed, it somehow executes the code on the Windows command line? Maybe I'm complicating it, but I hope you get the point, thanks, I'm waiting for an answer.
Answer the question
In order to leave comments, you need to log in
The dude wants to write a console utility in Java.
https://www.google.ru/search?q=java+console+app
The easiest option:
try {
// Execute command
String command = "cmd /c start cmd.exe";
Process child = Runtime.getRuntime().exec(command);
// Get output stream to write from it
OutputStream out = child.getOutputStream();
out.write("cd C:/ /r/n".getBytes());
out.flush();
out.write("dir /r/n".getBytes());
out.close();
} catch (IOException e) {
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question