Recently, the project saw the need to call other third-party tools in the Java program (such as calling third-party transcoding tools in the Program), so process emerged in this demand:
(I will briefly describe the usage and do not disclose the actual application)
1. Call. bat on Windows Platform
A. in disk F: The New a.txt file is "Love code ";
Create cmd. BAT and edit "Notepad F: \ a.txt"
B. Write the following call statement in the Java program:
Commandutil.exe C ("CMD/C start F: // cmd. Bat ");
The exec method of commandutil is as follows:
Public static Boolean exec (string command) throws ioexception, interruptedexception {log.info ("execution Script:" + command); Process = runtime.getruntime(cmd.exe C (command); int exitvalue = process. waitfor (); If (process! = NULL) {process. Destroy ();} If (exitvalue! = 0) {return false;} return true ;}
C. Run the program on the Windows platform. You can open notepad and see the word "love code;
2. Call the. Sh script on Linux.
In the same usage, you only need to replace the BAT file with the shell script file in Linux and call it with the same code.
Run a program on the Linux platform to call the shell script.