public class Main { public static void main(String[] args) { // TODO Auto-generated method stub String filePath = "D:/workspace/license/CodeTest/bin/test.bat"; try { Process p = Runtime.getRuntime().exec(filePath); p.waitFor(); InputStream in = p.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int c = -1; while((c = in.read()) != -1) { baos.write(c); } String response = new String(baos.toByteArray()); System.out.println("Response From Exe : "+response); } catch (Exception e) { e.printStackTrace(); } } }
파일을 Runtime.getRuntime().exe() 에 경로를 입력하여 실행 시키고
프로세스 객체에서 출력값을 얻어 출력한다.
실행 후 메모장을 닫아야 출력값이 출력된다.
'JAVA > JAVA 일반' 카테고리의 다른 글
JSONObject 순회 (0) | 2015.11.05 |
---|---|
List 정렬 (0) | 2015.11.05 |
Map의 순회 (0) | 2015.11.05 |
system.arraycopy (0) | 2015.05.22 |
Array <--> List 변환 (0) | 2015.01.21 |