ShellCommandExecutor { public static void execCmd(String command) { execCmd(command, command); } ShellCommandExecutor(String[] execString);  ShellCommandExecutor(String[] execString, File dir);  ShellCommandExecutor(String[] execString, File dir, Map<String, String> env);  ShellCommandExecutor(String[] execString, File dir, Map<String, String> env, long timeoutInSec); static void execCmd(String command); static void execCmd(String command, String description); static void execCmd(String command, File dir, Map<String, String> env, long timeoutInSec, String description); String[] getExecString(); int getExitCode(); String getOutput(); String toString(); Process getProcess(); boolean isCompleted(); boolean isTimedOut(); void setWorkDir(File dir); void setEnvironment(Map<String, String> environment); void execute(); final static long DEFAULT_TIMEOUT; }
@Test public void testExecCmdTimeout() { String command = "sleep 3; echo hello" ; try { ShellCommandExecutor.execCmd(command, null, null, 1, "timeout test"); } catch (Exception e) { System.out.println(e.getMessage()); } }
@Test public void testExecCmdFail() { String command = "echo failure >> /dev/stderr; exit 1"; try { ShellCommandExecutor.execCmd(command, null, null, 1, "timeout test"); } catch (Exception e) { System.out.println(e.getMessage()); } }