Java, inherit classpath with Runtime.exec() -
i have program create child process, , want inherit classpath parent. in javadoc, says:
public process exec(string[] cmdarray, string[] envp) throws ioexception
executes specified command , arguments in separate process specified environment.
given array of strings cmdarray, representing tokens of command line, , array of strings envp, representing "environment" variable settings, method creates new process in execute specified command.
if envp null, subprocess inherits environment settings of current process.
when set envp null, didn't inherit anything.
here code:
system.out.print("debug system path: "+system.getproperty("java.class.path")); starttime(); process proc = runtime.getruntime().exec(cmd,null);
i can see path information, these path information not inherited new created process.
how did specify classpath of application? if not through classpath environment variable, not inherited.
runtime.exec method can invoke native application, , envp here refers system environment, not java environment.
if want pass classpath child java process, can explicitly:
string[] cmdarray = new string[] { "java", "-classpath", system.getproperty("java.class.path"), "com.example.mychildapp", "appparam"}; process p = runtime.getruntime().exec(cmdarray);
Comments
Post a Comment