R
R
redasya2016-12-23 01:40:26
Java
redasya, 2016-12-23 01:40:26

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

3 answer(s)
_
_ _, 2016-12-23
@AMar4enko

The dude wants to write a console utility in Java.
https://www.google.ru/search?q=java+console+app

V
Vorh, 2016-12-23
@Vorh

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 question

Ask a Question

731 491 924 answers to any question