Fan Huan is a Java enthusiast.
Email: heydaymail@hotmail.com
Blog: http://heyday.blogone.net
2005-6-13
Reference address
Introduction
Java is a cross-platform language. We often encounter the need to call certain programs in windows through Java. Some third-party vendors such as ant also provide methods to call executable programs in windows, but we often need to call some batch processing commands. Java does not.
Here, I use a disguised call method so that Java can call the batch processing command. If you have a better method, please let me know.
BeforePreparations
Quick batch file (de) compiler
Compile any bat or cmd batch processing scripts into EXE files!
Start
1. Run the EXE file
Java JDK already provides calling methods, which are not cumbersome. The Code is as follows.
Try { String command ="Notepad"; Process child = runtime.getruntime(cmd.exe C (command ); } Catch (ioexception e ){ } |
2. Run the BAT (batch processing) File
Java does not support batch files. At the beginning, I have been studying how Java calls batch files, and I have never been able to find a solution. Later, we had to bypass the batch processing and consider how to convert the batch processing to an EXE executable file. Then call the executable file in Java.
Search on Google and find quick batch file (de) compiler. You can compile any bat or cmd batch processing scripts into EXE files. You can use it.
Quick batch file (de) compiler is easy to use:
Quickbfc file name. BAT file name. .exe (compile the batch processing command as an executable file)
Quickbfd file name. .exe file name. BAT (decompile executable files into batch processing commands)
Then, we can use Java to call the first method.
About the author
Fan Huan Java lovers, you can contact me through heydaymail@hotmail.com.
Email: heydaymail@hotmail.com
Blog: http://heyday.blogone.net