帮别人调试使用程序启动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。