I\'m working on a project, and it will give you a list of Windows commands. When you select one, it will perform that command. However, I don\'t know how to do that. I was g
This is a sample code to run and print the output of the ipconfig command in the console window.
import java.io.IOException;
import java.io.InputStream;
public class ExecuteDOSCommand {
public static void main(String[] args) {
final String dosCommand = "ipconfig";
try {
final Process process = Runtime.getRuntime().exec(dosCommand );
final InputStream in = process.getInputStream();
int ch;
while((ch = in.read()) != -1) {
System.out.print((char)ch);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Source: https://www.codepuran.com/java/execute-dos-command-java/