954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Process started with Runtime.getRuntime().exec() stops responding after a while

Hello,

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, OpenVPNis 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 !
TheAlchemist

the.alchemist
Newbie Poster
4 posts since Oct 2007
Reputation Points: 21
Solved Threads: 0
 

If openvpn writes a lot of output to stdin or stdout it can lock the process. When you say "capture streams" do you mean a Thread that reads them in real-time or just getting a handle to the file? The Thread is required to keep the buffers from filling up in the host system.

obdobion
Newbie Poster
1 post since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You