/** * java calling DOS command for Windows */public class RunDocInJava{ Public static void main (String[] args) { inputstream ins = null; string[] cmd = new String[] { "cmd.exe", "/C", "ipconfig" }; // Command line try { / /runtime.exec () used to execute external programs or commands Process Process = runtime.getruntime (). EXEC (cmd); ins = process.getinputstream (); // get information after executing the doc command //gets the information into the buffer as much as possible bUfferedreader reader = new bufferedreader (New inputstreamreader (INS)); String line = null; //Reading Information //will read the buffer information first, if the information is not fully read the source data while ((Line = reader.readline ()) != null) { system.out.println (line); } int exitval = process.waitfor (); //Get program return value success is "0" &nbsP System.out.println ("return integer: " +exitval); process.getoutputstream (). Close (), //if not closed in the program will cause a stack overflow } catch (exception e) { e.printstacktrace (); } }}
Perform:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/76/26/wKioL1ZMBuXRsohXAAI5aleHLFA058.jpg "title=" ~wn) Iahn5$ob2osbk~x%7t3.jpg "alt=" Wkiol1zmbuxrsohxaai5alehlfa058.jpg "/>
Some examples of the differences between Windows and Linux are called:
Windows downgrade program
Process proc =Runtime. GetRuntime (). exec ("exefile") ;
The Linux downgrade program will be changed to the following format
Process proc =Runtime. GetRuntime (). exec ("./exefile") ;
Windows downgrade system commands
String [] cmd={"cmd","/C","copy exe1 Exe2"};
Process proc =Runtime.GetRuntime().exec(cmd);
The Linux downgrade System command will be changed to the following format
String [] cmd={"/bin/sh","- C","ln-s exe1 Exe2"};
Process proc =Runtime.GetRuntime().exec(cmd);
Windows downgrades system commands and pops up a command-line window
String [] cmd={"cmd","/C","start copy exe1 exe2"};
Process proc =Runtime.GetRuntime().exec(cmd);
Linux downgrade system command and pop-up terminal window will be changed to the following format
String [] cmd={"/bin/sh","- C","xterm-e ln-s exe1 exe2"};
Process proc =Runtime.GetRuntime().exec(cmd);
and the working directory to set the calling program.
Process proc =Runtime.GetRuntime().exec("Exeflie",NULL, New File("Workpath"));
Examples of Windows and Linux call differences are referenced from: http://robinjoe.iteye.com/blog/1201388
This article is from "The rookie in the struggle ..." Blog, be sure to keep this source http://2015arong.blog.51cto.com/8994290/1713963
Calling the DOS shell command in a Java program--here, for example, invoking the doc command