java 另一個執行 shell script 的方法,使用 ProcessBuilder
import java.io.*;
import java.net.*;
import java.util.*;

public class runshell {
    public static void main(String a[]) throws Exception {
        String cmd = "ls";
        ProcessBuilder pb = new ProcessBuilder(cmd);
        Process pl = pb.start();
        String line = "";
        BufferedReader p_in = new BufferedReader(new InputStreamReader(pl.getInputStream()));
        while ((line = p_in.readLine()) != null) {
            System.out.println(line);
        }
        p_in.close();
    }
}

mark528 發表在 痞客邦 PIXNET 留言(0) 人氣()