This is an instance of calling a DOS command using Java code, where I'm not going to say, directly on the code, the code is as follows:
Copy Code code as follows:
Import java.io.*;
/**
* Java invoke DOS command for Windows
* Implement the ipconfig command that invokes windows, and then output the output to the console via IO flow.
*/
public class runwindowscommand{
public static void Main (string[] args) {
InputStream ins = null;
string[] cmd = new string[] {"cmd.exe", "/C", "ipconfig"}; Command
try {
Process process = Runtime.getruntime (). exec (CMD);
INS = Process.getinputstream (); Get information after executing the cmd command
BufferedReader reader = new BufferedReader (new InputStreamReader (INS));
String line = null;
while (line = Reader.readline ())!= null) {
System.out.println (line); Output
}
int exitvalue = Process.waitfor ();
System.out.println ("return value:" + exitvalue);
Process.getoutputstream (). Close (); Don't forget, you must shut it down.
catch (Exception e) {
E.printstacktrace ();
}
}
}