Java operation Bat file, starting Bat__java

Source: Internet
Author: User

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.

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.