Created
October 29, 2016 06:34
-
-
Save pethaniakshay/bdfc39c4ce8756f5bc3aabf1b262aac8 to your computer and use it in GitHub Desktop.
Run DOS Commands Using the Java Program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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