Noobish问题我确定,但我试图打开命令提示符,切换到一个目录,然后运行第二个命令。我有:Java - 打开命令提示符,运行两个命令
try {
// 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:\Users\Me\Desktop\Reports\Scripts /r/n".getBytes());
out.flush();
out.write("for %f in (*.txt) do type "%f" >> Export.txt /r/n".getBytes());
out.close();
} catch (IOException e) {
}
我无知的猜测是“%F”在第二个命令需要正确写的,但我知道的太少了有关Java我不知道该怎么做。
你需要转义引号,把'%f'写成'\'%f'' – Titus 2015-01-20 23:51:06
你对Java中的字符串转义(以及其他C语言的语言)有多少了解? – immibis 2015-01-20 23:53:23
@ immibis:谁多零。为工作做许多VBA并尝试冒险进入Java。 – TechnoWolf 2015-01-20 23:55:10