使用 Runtime.getRuntime().exec()
import java.io.*;
import java.net.*;
import java.util.*;
public class runshell {
public static void main(String a[]) throws Exception{
String cmd = "/bin/ls";
Process pl = Runtime.getRuntime().exec(cmd);
String line = "";
BufferedReader p_in = new BufferedReader(new InputStreamReader(pl.getInputStream()));
while ((line = p_in.readLine()) != null) {
System.out.println(line);
}
p_in.close();
}
}
沒有留言:
張貼留言