public class TestProxy {
public static void main(String[] args) {
TestProxy s = new TestProxy();
s.test();
}
public void test(){
Runtime run =Runtime.getRuntime();//获取runtime
try {
//执行命令
Process p = run.exec("ping www.baidu.com");
//获取输入流
InputStream ins= p.getInputStream();
//获取错误流
InputStream ers= p.getErrorStream();
//创建thread 参数是runnable ,并传入流
new Thread(new inputStreamThread(ins)).start();
p.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
class inputStreamThread implements Runnable{
private InputStream ins = null;
private BufferedReader bfr = null;
//获取流
public inputStreamThread(InputStream ins)
java 执行系统命令代码demo
最新推荐文章于 2023-10-08 14:29:38 发布