如何从java代码运行批处理文件?

时间:2014-04-25 06:56:23

标签: java windows

我尝试过以下代码,但没有任何反应。

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();

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

3 个答案:

答案 0 :(得分:0)

尝试:

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

答案 1 :(得分:0)

使用此:

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

答案 2 :(得分:0)

试试这个:

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