Java 외부명령어 실행하고 결과 불러오기 top2blue 2016. 3. 17. 15:08 import java.io.IOException; import java.util.Scanner; public class RuntimeEx { public static void main(String[] args) throws IOException { Process process = Runtime.getRuntime().exec("cmd /c dir/w"); Scanner sc = new Scanner(process.getInputStream(),"x-windows-949"); while (sc.hasNextLine()){ System.out.println(sc.nextLine()); } System.out.println(); sc.close(); String command[] = { "cmd ", "/c", "dir", "/w" }; process = Runtime.getRuntime().exec(command); sc = new Scanner(process.getInputStream(),"x-windows-949"); while (sc.hasNextLine()) System.out.println(sc.nextLine()); System.out.println(); sc.close(); process = new ProcessBuilder("cmd ", "/c", "dir", "/w").start(); sc = new Scanner(process.getInputStream(),"x-windows-949"); while (sc.hasNextLine()) System.out.println(sc.nextLine()); System.out.println(); sc.close(); String[] cmd = new String[] { "cmd ", "/c", "dir", "/w" }; process = new ProcessBuilder(cmd).start(); sc = new Scanner(process.getInputStream(),"ksc5601"); while (sc.hasNextLine()) System.out.println(sc.nextLine()); System.out.println(); sc.close(); } }