자바에서 외부파일을 실행시키거나, cmd 명령을 위해서 Runtime객체를 사용한다.
확장자가 .exe로 끝나는 외부파일을 실행시킬때에는
try {
Process process = Runtime.getRuntime().exec("c:/windows/notepad.exe");
} catch (IOException e1) {
System.out.println(e1);
}
Process process = Runtime.getRuntime().exec("c:/windows/notepad.exe");
} catch (IOException e1) {
System.out.println(e1);
}
로 실행시키면된다.
하지만 .exe로 끝나는 파일이 아니면 (예:.mov)
try {
Process process = Runtime.getRuntime().exec("cmd /c d:/test/test.mov");
} catch (IOException e1) {
System.out.println(e1);
}
Process process = Runtime.getRuntime().exec("cmd /c d:/test/test.mov");
} catch (IOException e1) {
System.out.println(e1);
}
로 실행시켜 줘야한다.
======================================================================
여기에서 process는 cmd창의 Stream을 얻어온다.
cmd창 실행 후 계속 할일이 있다면 process를 이용하면 된다.
댓글 없음:
댓글 쓰기