简体   繁体   中英

how to run batch file from java code?

I've tried the following codes but nothing happens.

List cmdAndArgs = Arrays.asList({"cmd", "/c", "simple.bat"});
String dir ="E:\\SK\\EXTRA KNOWLEDGE\\JAVA\\RUN OTHER APP";

ProcessBuilder pb = new ProcessBuilder(cmdAndArgs);
pb.directory(new File(dir));
Process p = pb.start();

and

Process process = Runtime.getRuntime().exec("notepad.exe"); 

尝试:

Runtime.getRuntime().exec("cmd /c start YourBatch.bat");

用这个:

Runtime.getRuntime().exec("cmd.exe", "/c", "./users/batch.bat");

尝试这个:

    Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", "simple.bat"});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM