import java.io.*; public class Test { public static void main(String args[]) { Process p = null; try { p = Runtime.getRuntime().exec(args[0]); Flusher errorFlusher = new Flusher(p.getErrorStream()); errorFlusher.start(); try { p.waitFor(); } catch(InterruptedException ignored) {} if(errorFlusher.readData()) { System.out.println("Read data on stderr."); } } catch(IOException ignored) { } finally { if(p != null) p.destroy(); } } private static class Flusher extends Thread { private BufferedReader m_reader; private boolean m_readData; public Flusher(InputStream stream) { m_readData = false; m_reader = new BufferedReader(new InputStreamReader(stream)); } public synchronized void run() { try { String line = m_reader.readLine(); // will block if no data is available m_readData = (line != null); // Suck up all of the data while(line != null) { line = m_reader.readLine(); } } catch(IOException ignored) {} } public synchronized boolean readData() { return m_readData; } } }