How to call executable files and batch processing commands in Java

Source: Internet
Author: User

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.

Preparations [/B]
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

Related Article

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.