[JAVA100 example]041, execute system command

Source: Internet
Author: User
 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.