用Runtime这个类啊
public class SystemConsole implements Runnable{private InputStream inputStream;public void SetInputStream(InputStream is){this.inputStream=is;}@Overridepublic void run() {try { BufferedReader reader = new BufferedReader( new InputStreamReader(this.inputStream)); String line = null; while ((line = reader.readLine()) != null) { System.out.println(line); } } catch (Exception e) { e.printStackTrace(); } }public static void main(String args[]) throws IOException{String cmdArray = "ping 127.0.0.1";Runtime rt = Runtime.getRuntime();Process prcs =rt.exec(cmdArray);SystemConsole sc = new SystemConsole();sc.SetInputStream(prcs.getInputStream());new Thread(sc).start();}}
取消
评论