1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; public class RuntimeTest{ public static void main (String args []) throws Exception{ if (args.length==0) { System.exit(1); } String command = args[0]; Runtime run = Runtime.getRuntime(); Process pro = run. exec(command); InputStreamReader in = new InputStreamReader(pro.getInputStream()); BufferedReader buff = new BufferedReader(in); for(String temp = buff.readLine();temp!=null;temp=buff.readLine()){ System.out.println(temp); } buff .close(); in.close(); } }
|