Java calls some programs under windows

Java calls some programs under windows

Java is a cross-platform language, and we often encounter the need to call certain programs under windows through Java. Some third-party vendors, such as (ANT), also provide methods to call executable programs under windows, but we often need to call some batch commands. Java does not provide it. Here, I use a disguised calling method to enable Java to call batch commands.
  Preliminary preparation
  Quick Batch File (De)Compiler
  compiles any BAT and CMD batch scripts into EXE files.
  1. Run the exe file
  Java JDK has provided the calling method, which is not cumbersome. The code is as follows.
  
Java code Copy code
  1. try {   
  2.   String command = "notepad";   
  3.   Process child =   
  4.   Runtime.getRuntime().exec(command);   
  5.   } catch (IOException e)   
  6.   {   
  7.   }  

  2. Run bat (batch processing) file
  Java does not support batch processing file yet. I have been studying how to call batch files in Java at the beginning, but I can't find a solution. Later, I had to bypass the batch process and consider how to convert the batch process into an exe executable file. Then call the executable file through Java.
  Search on Google and find Quick Batch File (De)Compiler, you can compile any BAT, CMD batch script into an EXE file. After using it, it really works.
  Quick Batch File (De)Compiler is very simple to use:
  Quickbfc file name.bat file name.exe (compile batch commands into executable files)
  quickbfd file name.exe file name.bat (decompile executable files into batch Command)
  Then, we can call it through Java according to the first method.

Guess you like

Origin blog.csdn.net/geggegeda/article/details/3503124