0

I have Runtime.getRuntime().exec( cmd ) to run an exe file that downloads a content from another server.

but the program fails to connect to another server due to timeout.

seemingly the Runtime.getRuntime().exec( cmd ) does not use the proxy set in the JVM. It works when i set export https_proxy="host:port" manually on the server. Could you please suggest how to resolve it?

System.setProperty( "https.proxyHost", "host" )
System.setProperty( "https.proxyPort", "port" )
Runtime.getRuntime().exec( "test.exe" ) >> fails to download a content from an external server
  • 3
    [this?](https://stackoverflow.com/a/8607281/1059372) – Eugene Apr 03 '21 at 01:36
  • `export https_proxy="host:port"` is basically the right answer, and your Java program should not be hard coding `System.setProperty( "https.proxyHost", "host" );`. Proxy config should be the sysadmin's responsibility, and not the individual program's. – that other guy Apr 03 '21 at 01:57
  • @Eugene how can sub process reuse the environment proxy configured in the main process? `Runtime runtime = Runtime.getRuntime(); Process p = runtime.exec( "/bin/sh -c export https_proxy", new String[] { "https_proxy=host:port" } ); p.waitFor(); p = runtime.exec( "exe" ); << this is the new process and still not working p.waitFor();` otherwise another option is to run a sh file. – Jackie chen Apr 03 '21 at 02:08
  • 1
    `/bin/sh -c export https_proxy` creates a new shell and alters that shell. It does not change the initiating process. Since the main process has not been altered, there is nothing to reuse in a sub process. And why don’t you just provide the `new String[] { "https_proxy=host:port" }` argument to the actual `exec` call? No-one suggested to make two `exec` calls. – Holger Apr 06 '21 at 13:01

0 Answers0