我正在尝试通过Java执行命令行参数。例如:
// Execute command
String command = "cmd /c start cmd.exe";
Process child = Runtime.getRuntime().exec(command);
// Get output stream to write from it
OutputStream out = child.getOutputStream();
out.write("cd C:/ /r/n".getBytes());
out.flush();
out.write("dir /r/n".getBytes());
out.close();
上述代码打开了命令行但没有执行cd
或dir
。有任何想法吗?我正在运行Windows XP,JRE6。
(我已经修改了我的问题以使其更加具体。下面的答案虽然有用,但并未回答我的问题。)
exec()
调用中运行多个shell命令。我不确定此时你还有什么不满意的地方。 - Andrzej Doyle