1
我需要在運行時啓動另一個Java程序,這是我的代碼運行Exec的變化路徑
try {
String cmd2 = "java -jar c:\\test\\deploy\\framework_e_app.jar";
Process p = Runtime.getRuntime().exec(cmd2);
BufferedReader in = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.print("<STDOUT>");
System.out.print(line);
System.out.println("</STDOUT>");
}
InputStream stderr = p.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line2 = null;
System.out.print("<STDERROR>");
while ((line2 = br.readLine()) != null)
System.out.print(line2);
System.out.println("</STDERROR>");
} catch (IOException e) {
e.printStackTrace();
}
這是我得到了它的工作的唯一途徑,而是因爲它搜索在當前配置文件很煩人路徑。
我試圖用這個作爲CMD2:
String[] cmd2 = new String[4];
cmd2[0] = "cmd";
cmd2[1] = "/C";
cmd2[2] = "cd test\\deploy";
cmd2[3] = "java -jar framework_e_app.jar";
我不能讓工作目錄的變化。什麼是正確的語法? (很明顯,在Windows環境中,我是Im)。
是不是這個窗口的方式做這個'cmd2 [1] =「C:」;'但我不確定... – jlordo