public class EnvEcho {
public static void main(String[] args) {
System.out.println("EnvEcho http_proxy: " + System.getenv("http_proxy"));
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class EnvSub {
public static void main(String[] args) throws Exception {
System.out.println("main http_proxy: " + System.getenv("http_proxy"));
Process sub = Runtime.getRuntime().exec("java EnvEcho");
BufferedReader reader = new BufferedReader(new InputStreamReader(sub.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println("\tsub: "+ line);
}
}
}
➜ tmp java EnvSub
main http_proxy: http://10.199.75.12:8080
sub: EnvEcho http_proxy: http://10.199.75.12:8080
➜ tmp proxy -j
http_proxy: http://10.77.145.90:11328
https_proxy: http://10.77.145.90:11328
➜ tmp java EnvSub
main http_proxy: http://10.77.145.90:11328
sub: EnvEcho http_proxy: http://10.77.145.90:11328