幫別人調試使用程序啓動tomcat,開始寫以下: apache
Runtime r = Runtime.getRuntime(); tomcat
Process p = r.exec("D:/桌面的東西/tomcat/apache-tomcat-6.0.35/bin/startup.bat"); this
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream(), "gbk")); spa
String str = "";
while((str = br.readLine()) != null)
{
System.out.println(str);
}
br.close();
r.gc(); 調試
有事沒事拉出來走兩步,出現以下問題: orm
The CATALINA_HOME environment variable is not defined correctly
This environment variable is needed to run this program 繼承
有點鬱悶了……咋一看,CATALINE_HOME環境變量有問題。配置修改爲路徑後,繼續走兩步,未果。。。。。 進程
他大爺的,運行的內部機制是什麼呢???按住Ctrl + 鼠標點擊這個exec()方法。大家多態的exec()方法6個。挨個看了看。 ci
看到這個方面,註解以下: element
* @param command a specified system command.
*
* @param envp array of strings, each element of which
* has environment variable settings in the format
* <i>name</i>=<i>value</i>, or
* <tt>null</tt> if the subprocess should inherit
* the environment of the current process.
*
* @param dir the working directory of the subprocess, or
* <tt>null</tt> if the subprocess should inherit
* the working directory of the current process.
dir 子進程的工做目錄;若是子進程應該繼承當前進程的工做目錄,則該參數爲 null 。
public Process exec(String command, String[] envp, File dir) throws IOException{}
因而修改exec()中的參數以下:
Process p = Runtime.getRuntime().exec("cmd /c start D:\\桌面的東西\\tomcat\\apache-tomcat-6.0.35\\bin\\catalina.bat start", null, new File("D:\\桌面的東西\\tomcat\\apache-tomcat-6.0.35"));
繼續拉出來走兩步,,,,,,,,,
OK。