I'm currently developping a GUI OpenVPN wrapper in Java ( platform is WinXP ).
I'm having a problem when I launch OpenVPN using Java Runtime.getRuntime().exec(), a problem I have been trying to solve for the 2 past days but in vein :yawn:
Here is the code I'm using to launch OpenVPN:
//... String cmd = "openvpn --config myConfigFile.ovpn --management 127.0.0.1 9006 --management-query-passwords"; Process v = Runtime.getRuntime().exec(cmd); //.. connect to managemant console, enter username and pass etc //... capture input stream & output stream to my program etc
Now, from the output and input I capture from the Process v, OpenVPN connects normally with no issues, & I can use & browse the Internet with no problems whatsoever; However, after a while ( <5 mins ), OpenVPN simply stops responding !
I found this in the Java Doc, but I'm not sure if it's related :
The Runtime.exec methods may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts.
In my case, OpenVPN is kinda a daemon process. It connects, and keeps running & updating connections when necessary, till it's stopped by the user.
Does anyone have any idea what's happening ?
Is it because Process isn't supposed to launch programs such as OpenVPN ?
or is it a thread-related issue ? ( I tried v.waitFor(); and it froze the whole program )
Is there an alternative way to launch processes such as OpenVPN from Java ?
( By the way, it's not an OpenVPN issue, because when I launch OpenVPN from the Win command line it works perfectly fine, so I'm quite sure it's related to either threading / Process ? )
Thanks in advance for any help !