Haha, I just solved the example of running the command line in C # For the customer, and sorted out the Java example by the way. Let's take a look at the comparison.
Java
Import Java. io. bufferedreader; <br/> Import Java. io. inputstream; <br/> Import Java. io. inputstreamreader; <br/>/** <br/> * example of running command line in Java <br/> * @ author Java century network (java2000.net) <br/> */<br/> public class testprocess {<br/> Public static void main (string [] ARGs) {<br/> try {<br/> // if you need to start the CMD window, use <br/> // CMD/K start to ping 127.0.0.1-T <br/> PROCESS p = runtime.getruntime(cmd.exe C ("Ping 127.0.0. 1-T "); <br/> inputstream is = P. getinputstream (); <br/> bufferedreader reader = new bufferedreader (New inputstreamreader (is); <br/> string line; <br/> while (line = reader. readline ())! = NULL) {<br/> system. out. println (line); <br/>}< br/> P. waitfor (); <br/> is. close (); <br/> reader. close (); <br/> P. destroy (); <br/>}catch (exception ex) {<br/> ex. printstacktrace (); <br/>}< br/>}
C #
Using system; <br/> using system. collections. generic; <br/> using system. text; <br/> using system. diagnostics; <br/> using system. io; <br/>/** <br/> * C # example of running command line <br/> * @ author Java century network (java2000.net) <br/> */<br/> namespace consoleapplication1 <br/> {<br/> class testprocess <br/>{< br/> Public static void executecommand () <br/>{< br/> processstartinfo start = new processstartinfo ("ping.exe "); // Set the command line file for running the ping.exe file. The file system will find it by itself <br/> // if it is a temporary exefile, you can refer to it for details, such as running winrar.exe <br/> Start. arguments = "127.0.0.1-T"; // set the command parameter <br/> Start. createnowindow = true; // do not display the doscommand line window <br/> Start. redirectstandardoutput = true; // <br/> Start. redirectstandardinput = true; // <br/> Start. useshellexecute = false; // whether to specify the Operating System Shell Process Startup Program <br/> PROCESS p = process. start (start); <br/> streamreader reader = P. standar Doutput; // capture the output stream <br/> string line = reader. Readline (); // read a row each time <br/> while (! Reader. endofstream) <br/>{< br/> console. out. writeline (line); <br/> line = reader. readline (); <br/>}< br/> P. waitforexit (); // wait for the program to exit after execution <br/> P. close (); // close the Process <br/> reader. close (); // close the stream <br/>}< br/>
The running results are the same. Let's take a look.