Import java.io.*/** * <p>title: Run system command </p> * <p>description: Run a system command to demonstrate the use of the runtime class. </p> * <p>copyright:copyright (c) 2003</p> * <p>Filename:CmdExec.java</p> * @version 1.
0/public class CmdExec {/** *<br> Method Description: Constructor, run system command *<br> input parameter: String cmdline command character *<br> return type: * *
Public CmdExec (String cmdline) {try {string line;
Run System command Process p = runtime.getruntime (). exec (CmdLine);
Use the cached input stream to get the screen output.
BufferedReader input = new BufferedReader (New InputStreamReader (P.getinputstream ()));
Reads the screen output while (line = Input.readline ())!= null) {System.out.println ("Java print:" +line);
//Close the input stream input.close ();
catch (Exception err) {err.printstacktrace (); /** *<br> Method Description: Main method *<br> input parameter: *<br> return type: */public static void Main (String argv[]) {new Cm
Dexec ("Myprog.bat"); }
}
JAVA100 Example Thematic index page