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();
}
}
Happy coding.
The secret to creativity is knowing how to hide your sources.— Albert Einstein
Good artists copy, great artists steal. – Pablo Picasso
2013年1月31日 星期四
java execute shell script [use ProcessBuilder]
java 另一個執行 shell script 的方法,使用 ProcessBuilder
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言