Skip to content

Instantly share code, notes, and snippets.

@pethaniakshay
Created October 29, 2016 06:34
Show Gist options
  • Save pethaniakshay/bdfc39c4ce8756f5bc3aabf1b262aac8 to your computer and use it in GitHub Desktop.
Save pethaniakshay/bdfc39c4ce8756f5bc3aabf1b262aac8 to your computer and use it in GitHub Desktop.
Run DOS Commands Using the Java Program
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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment