I'm writing a program that forms a new sub-process in a following pattern:
proc = java.lang.Runtime.getRuntime().exec("java -jar Xxx.jar");
Though the environment variables are automatically inherited to sub-processes, I think the system properties defined by -D<name of property>=<value of the property>
are not.
My question is, if there is any way to transfer the system properties programmatically. Any comments or answers are welcomed. Thanks.
One solution that I've come up with is to define a set of properties to pass to subprocesses, and create a -D<key>=<value>
strings from it.
static String[] properties_to_pass = {
"log4j.configuration"
};
Above is the set of system properties to pass. Then...
StringBuffer properties = new StringBuffer();
for ( String property : properties_to_pass ) {
String value = System.getProperty(property);
if ( value != null ) {
String r = String.format("-D%s=%s ", property, value);
properties.append( r );
}
}
And after the above ...
String command_arg = properties.toString();
String command = String.format("java %s -jar Torpedo.jar", command_arg);
java.lang.Runtime.getRuntime.exec( command );
Very naive solution, but works anyway. But still not sure that there might be a better solution. Any further comments are welcomed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With