자바에서 외부 프로그램을 로딩 및 처리하는 프로세스 클래스인 Process 클래스의 멤버 메쏘드로 waitFor()가 있는데, 자꾸 hang이 걸립니다.. ^^;; 몇번을 간단하게 테스트 했는데도 계속 hang이 걸리네요...... ^^;; 코드를 아래와 같이 고치면 해결이 됩니다.. ^^
- try
- {
- Runtime runtime= Runtime.getRuntime();
- Process process= runtime.exec("javac *.java");
- java.io.InputStream is= process.getInputStream();
- java.io.BufferedReader br=new java.io.BufferedReader(new java.io.InputStreamReader(is));
- String tmp;
- while ( !( (tmp=br.readLine()) == null ))
- {
- System.out.println(tmp);
- }
- br.close();
- is.close();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
참고로..
Runtime Class
- public static Runtime getRuntime()
- public void exit(int status)
- public Process exec(String command) throws IOException
- public Process exec(String command, String envp[]) throws IOException
- public Process exec(String cmdarray[]) throws IOException
- public Process exec(String cmdarray[], String envp[]) throws IOException
- public native long freeMemory()
- public native long totalMemory()
Process Class
- public abstract OutputStream getOutputStream()
- public abstract InputStream getInputStream()
- public abstract InputStream getErrorStream()
- public abstract int waitFor() throws InterruptedException
- public abstract int exitValue()
- public abstract void destroy()
|