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();
    }
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 mark528 的頭像
    mark528

    狐的窩

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