EdtheN3rd
EdtheN3rd

Reputation: 3

Inputting a command to cmd with Java

I am trying to make a Java script where the user can type a command from the Java console in Eclipse, and the command will be sent to the cmd. For example, when you run the program, the console will ask the user what command they want to use, and the command they put in will be sent to the cmd.

Upvotes: 0

Views: 85

Answers (2)

rob
rob

Reputation: 1286

You can use a Scanner ( see this link ) to get the command

Then use Runtime.getRuntime().exec(command); to execute it

Upvotes: 1

AHH
AHH

Reputation: 1083

Console console = System.console();
String com = console.readLine("Enter command:");
Process child = Runtime.getRuntime().exec(com);

Upvotes: 1

Related Questions