3

我有一个批处理文件:

@echo off
cd %AppData%\.minecraft
start javaw -Xms1024m -Xmx1024m -Djava.library.path="\bin\natives" -classpath "bin\minecraft.jar;bin\jinput.jar;bin\lwjgl.jar;bin\lwjgl_util.jar" net.minecraft.client.Minecraft Flood2d

我如何编写它以从 ProcessBuilder 开始?

4

1 回答 1

0

如果你真的想要 ProcessBuilder 这里是:

File workdir = new File(System.getenv("AppData"));
Process p = new ProcessBuilder().directory(workdir).command("cmd", "/c", "start", "javaw", "-Xms1024M", ......).start();

但 Runtime.exec() 也适合这项工作:

Process p = Runtime.getRuntime().exec("cmd /c start ......", null, workdir);

注意:我们需要 "cmd /c start" 因为 start 不是一个应用程序,它是一个 cmd 的命令

于 2012-11-22T07:42:55.053 回答