@Test public void testExecute_Empty_Command() throws Exception { String command = ""; exception.expect(java.lang.IllegalArgumentException.class); Result result = CommandExecutor.executeCommand(command); assertEquals(1, result.getExitVal()); assertNotNull(result); }
public static Result executeCommand(String... command) throws IOException, InterruptedException { Result rs = new Result(); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(command); StreamWrapper error = new StreamWrapper(proc.getErrorStream()); StreamWrapper output = new StreamWrapper(proc.getInputStream()); error.start(); output.start(); error.join(SLEEP_TIME); output.join(SLEEP_TIME); proc.waitFor(); rs.setExitVal(proc.exitValue()); rs.setOutput(output.getMessage()); rs.setError(error.getMessage()); proc.destroy(); return rs; }
CommandExecutor { public static Result executeCommand(String... command) throws IOException, InterruptedException { Result rs = new Result(); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(command); StreamWrapper error = new StreamWrapper(proc.getErrorStream()); StreamWrapper output = new StreamWrapper(proc.getInputStream()); error.start(); output.start(); error.join(SLEEP_TIME); output.join(SLEEP_TIME); proc.waitFor(); rs.setExitVal(proc.exitValue()); rs.setOutput(output.getMessage()); rs.setError(error.getMessage()); proc.destroy(); return rs; } }
CommandExecutor { public static Result executeCommand(String... command) throws IOException, InterruptedException { Result rs = new Result(); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(command); StreamWrapper error = new StreamWrapper(proc.getErrorStream()); StreamWrapper output = new StreamWrapper(proc.getInputStream()); error.start(); output.start(); error.join(SLEEP_TIME); output.join(SLEEP_TIME); proc.waitFor(); rs.setExitVal(proc.exitValue()); rs.setOutput(output.getMessage()); rs.setError(error.getMessage()); proc.destroy(); return rs; }  }
CommandExecutor { public static Result executeCommand(String... command) throws IOException, InterruptedException { Result rs = new Result(); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(command); StreamWrapper error = new StreamWrapper(proc.getErrorStream()); StreamWrapper output = new StreamWrapper(proc.getInputStream()); error.start(); output.start(); error.join(SLEEP_TIME); output.join(SLEEP_TIME); proc.waitFor(); rs.setExitVal(proc.exitValue()); rs.setOutput(output.getMessage()); rs.setError(error.getMessage()); proc.destroy(); return rs; }  static Result executeCommand(String... command); static Result executeCommand(String command); }
CommandExecutor { public static Result executeCommand(String... command) throws IOException, InterruptedException { Result rs = new Result(); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(command); StreamWrapper error = new StreamWrapper(proc.getErrorStream()); StreamWrapper output = new StreamWrapper(proc.getInputStream()); error.start(); output.start(); error.join(SLEEP_TIME); output.join(SLEEP_TIME); proc.waitFor(); rs.setExitVal(proc.exitValue()); rs.setOutput(output.getMessage()); rs.setError(error.getMessage()); proc.destroy(); return rs; }  static Result executeCommand(String... command); static Result executeCommand(String command);  }