[Development tips] Java calls executable programs and batch processing commands

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.

 

 

 

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

 

 

 

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.