I wanted to run .cmd file from java. Do I have something that works for me, does someone help me understand the potential failures of my schedule?
Import java.io.IOException; / * How to run a batch .bat or .cmd file from java? 1. I do not want to open the command window. It should be in the background 2. Gracefully destroyed any new process. 3. Experts need to confirm the quality of the program. * / Public class runbat {public static zero main (string agre []) {runtime run = runtime.Tet timetable (); // Best possible way I found that to build a command that you want to execute as // string and it is used in exec. If the batch file creates an array of string commands in the command line argument / command and moves the array as an input method in the form of an app method of //. This order can also be passed externally as the input of the method. Process p = null; String cmd = "d: \\ database \\ TableToCSV.cmd"; Try {p = run.exec (cmd); P.getErrorStream (); Println ("RUN.COMPLETED.SUCCESSFULLY"); } Hold (IOException e) {e.printStackTrace (); Println ("ERROR.RUNNING.CMD"); P.destroy (); }}} Is my solution reliable? How can I ensure that. CMD can be executed once.
Thank you.
I do not know what you're doing with P; getErrorStream (), you do not overwhelm it Are there.
p = run.exec (cmd)); P.waitFor (); Println (p.exitValue ()); And finally put p.destroy () in the block.
Hope it helps.
Comments
Post a Comment