Runtime

java core 2005. 6. 6. 10:30

Runtime 을 reflection으로 구해 실행시키는 코드

 

import java.util.*;
import java.io.*;
import java.lang.reflect.*;

public class RuntimeTest {

    Method exec;
    public RuntimeTest() throws NoSuchMethodException {
        exec = Runtime.class.getMethod("exec",
                new Class[] {String[].class, String[].class, File.class});
    }

    public Process exec() {
        String[] cmd = new String[] { "gcc", "-c",
            "a.c",
            "b.c"
        };
        String[] env = null;
        File workingDir = new File("./working/b");

        try {
            Object[] arguments = {cmd, env, workingDir};
            return (Process) exec.invoke(Runtime.getRuntime(),
                                                 arguments);
        } catch (InvocationTargetException exc) {
            exc.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) throws Exception  {
        RuntimeTest rt = new RuntimeTest();
        rt.exec();
    }
}

'java core' 카테고리의 다른 글

[펌] JVM 관련  (0) 2005.09.15
[TIP]자바 실행, 컴파일때 shell 이용법  (0) 2005.06.11
millisecond를 가지고 구하기  (0) 2005.05.13
java 5.0 enum.  (0) 2005.05.12
jdk 5.0 static import test code  (0) 2005.05.11
Posted by '김용환'
,