import java.io.*; class LeitoraDeProcesso implements Runnable { Process p; public LeitoraDeProcesso(Process proc) { p = proc; } public void run() { try{ DataInputStream di = new DataInputStream(p.getInputStream()); String line = null; while ((line = di.readLine()) != null) System.out.println(line); } catch(Exception e) { System.out.println("TLeitora" + e);} try { p.waitFor(); } catch(InterruptedException ie) { System.out.println("TLeitoraWait" + ie); }; } } class LeitoraDeErros implements Runnable { Process p; public LeitoraDeErros(Process proc) { p = proc; } public void run() { try { DataInputStream d = new DataInputStream(p.getErrorStream()); String line = null; while ((line = d.readLine()) != null) System.out.println(line); } catch(Exception e) { System.out.println("TErros" + e); }; try { p.waitFor(); } catch(InterruptedException ie) { System.out.println("TErrosWait" + ie); }; } } public class TesteExec { public static void main(String s[]) { Runtime r = Runtime.getRuntime(); try { Process p = r.exec("ping localhost"); // funciona // Process p = r.exec("dir *"); // da erro na criacao // Process p = r.exec("type UsaNodo.java"); // da erro na criacao LeitoraDeProcesso le1 = new LeitoraDeProcesso(p); Thread tle1 = new Thread(le1); tle1.start(); // inicia uma thread para ler o resultado LeitoraDeErros ler1 = new LeitoraDeErros(p); Thread tler1 = new Thread(ler1); tler1.start(); // inicia uma thread para ler os erros tle1.join(); tler1.join(); // espera o final das duas threads } catch(Exception e) { System.out.println("Excecao Teste: " + e);} } }