Sometimes this happens when you open a . bat batch file on a daily basis, and you choose to use a Windows task plan or a program startup, but this is often the case with Windows Task Scheduler, which causes the . Bat The file does not start on time, so you need some programs, and here I'll share how to use Java to start the . bat file.
Package Com.app;
Import java.io.IOException;
public class Startcmd {public
static void Main (string[] args) {
String cmd = "cmd/c start e:\\bats\\mainthread.b At ";
try {
Process PS = Runtime.getruntime (). exec (cmd);
Ps.waitfor ();
} catch (IOException IoE) {
ioe.printstacktrace ();
} catch (Interruptedexception e) {
e.printstacktrace ( );
}
}
}
The contents of the . bat file, where exit indicates that the CMD window is automatically exited after the program finishes running.
@echo off
Java-jar E:\Bats\Mainthread.jar
exit
So tell me about a . bat file started, with special attention to the . bat file must be the path of the program that will be executed as written above Java E:\Bats\Mainthread.jar, Or you'll report a jarfile error.