使用Java调用外部程序

public class TestCommand extends TestCase {

    public void testEchoCommand() throws Exception{
        String cmd = "cmd /c echo lee";
        Process process = Runtime.getRuntime().exec(cmd);
        process.waitFor();
        int ret = process.exitValue();
        System.out.println("exit value is " + ret);
       
        InputStream is = process.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
       
        String line = br.readLine();
       
        br.close();
        is.close();
       
        assertEquals("lee", line);
    }
}

你可能感兴趣的:(使用Java调用外部程序)