爪哇:
public static void startCmd(String path)
{
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(path);
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(), "cp852"));
String line = null;
// redirection output to console
while((line = input.readLine()) != null) {
System.out.println(line);
}
System.out.println("Error code: " + pr.waitFor());
}
public static void main(String[] args) {
startCmd("c:\\run.bat");
}
运行.bat:
cd c:\cmd\
application.exe
控制台输出:
D:\WORKSPACE\TEST>cd c:\cmd\
D:\WORKSPACE\TEST>application.exe // path should be changed from D:\WORKSPACE\TEST> to c:\cmd>
Error code: 0
为什么cd c:\cmd\
命令没有传递给 java 控制台应用程序???