[참고 사이트] http://efreedom.com/Question/1-7112259/Execute-Windows-Commands-Using-Java-Change-Network-Settings
자바를 사용 하 여 창 명령을 실행할 수 있을 싶어요. 문제의 명령 netsh
는입니다. 이 설정/리셋 내 IP 주소를 날 수 있게 된다.
참조:
참고 내가 배치 파일을 실행 하 고 싶지 않아 .
참조:
배치 파일을 사용 하는 대신 직접 그러한 명령을 실행 하 고 싶습니다. 이것은 가능?
감사.
나중에 참조할-구현된 솔루션
public class JavaRunCommand {
private static final String CMD =
"netsh int ip set address name = \"Local Area Connection\" source = static addr = 192.168.222.3 mask = 255.255.255.0";
public static void main(String args[]) {
try {
// Run "netsh" Windows command
Process process = Runtime.getRuntime().exec(CMD);
// Get input streams
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
// Read command standard output
String s;
System.out.println("Standard output: ");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// Read command errors
System.out.println("Standard error: ");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}