Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Updating text widget from stdOut

Hi,

 

I’m trying to write a simple client for OpenVPN using SWT, and want to redirect the output from the command into a text widget.

 

The client needs to continue to respond after the command has been issued.

 

I am reading the stdOut from the command like this:

 

p = Runtime.getRuntime().exec( … path to openvpn … ) );

BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );

 

br.readLine() blocks when there is nothing coming, so any loop will result in deadlock, because the openvpn process stays executing.

 

I tried putting the block in a Runnable like this:

 

d.syncExec( new Runnable() {

                             

public void run() {

                             

      BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );

            String line;

            try {

                                         

                  while ( (line = br.readLine()) != null)

                        logWnd.append(line+"\n");

                                         

            } catch(IOException e) {}

      }

                             

} );

 

But the GUI program hangs when OpenVPN stops outputting to stdOut.

Can anyone help me with the correct way to do something like this?

 

Thanks

Etienne Le Sueur

 


Back to the top