0. runtime.exe C () is used to execute external programs or commands
1. runtime.exe C () has four call Methods
* Public process exec (string command );
* Public process exec (string [] cmdarray );
* Public process exec (string command, string [] envp );
* Public process exec (string [] cmdarray, string [] envp );
2. Get the return value of program execution. 0 is success.
You need to use the waitfor () function, such
PROCESS p = runtime.getruntime(cmd.exe C ("javac ");
(Processing .....)
Int exitval = P. waitfor ();
3. Get the execution result or error message.
You must use bufferedinputstream and bufferreader to obtain the data. Otherwise, the program will
For example, if you get the error message, use P. geterrorstream () and then output it:
Bufferedinputstream in = new bufferedinputstream (P. geterrorstream ());
Bufferedreader BR = new bufferedreader (New inputstreamreader (in ));
4. runtime.exe C () is not the same as directly executing the command line command!
Ah, I have suffered a lot here. Runtime.exe C () has limitations. For some commands, you cannot directly pass the content in command line as a string parameter to Exec ().
Such as redirection. For example:
Javap-l XXX> output.txt
In this case, the second type of exec overload is used, that is, the input parameter is string []:
PROCESS p = runtime.getruntime(cmd.exe C (New String [] {"/bin/sh", "-c", "javap-l XXX> output.txt "});
Reprinted please indicate the source of this article: http://blog.csdn.net/flying881114/archive/2011/03/23/6272472.aspx