在Java中,可能看起来像-
public static void main(String[] args) { try { Process p = Runtime.getRuntime().exec("/bin/ls"); final InputStream is = p.getInputStream(); Thread t = new Thread(new Runnable() { public void run() { InputStreamReader isr = new InputStreamReader(is); int ch; try { while ((ch = isr.read()) != -1) { System.out.print((char) ch); } } catch (IOException e) { e.printStackTrace(); } } }); t.start(); p.waitFor(); t.join(); System.out.println("Child Complete"); } catch (Exception e) { e.printStackTrace(); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)