public static String execToString(String command) throws Exception {
  CommandLine commandline=CommandLine.parse(command);
  ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
  PumpStreamHandler streamHandler=new PumpStreamHandler(outputStream);
  DefaultExecutor exec=new DefaultExecutor();
  exec.setExitValues(null);
  exec.setStreamHandler(streamHandler);
  exec.setWatchdog(new ExecuteWatchdog(5000));
  try {
    exec.execute(commandline);
    return (outputStream.toString());
  }
 catch (  Exception e) {
    throw new Exception(String.format("%s - %s",outputStream.toString(),e.getMessage()));
  }
}

public static String execToString ( String command ) throws Exception { CommandLine commandline = CommandLine . parse ( command ) ; ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ; PumpStreamHandler streamHandler = new PumpStreamHandler ( outputStream ) ; DefaultExecutor exec = new DefaultExecutor ( ) ; exec . setExitValues ( null ) ; exec . setStreamHandler ( streamHandler ) ; exec . setWatchdog ( new ExecuteWatchdog ( 5000 ) ) ; try { exec . execute ( commandline ) ; return ( outputStream . toString ( ) ) ; } catch ( Exception e ) { throw new Exception ( String . format ( "%s - %s" , outputStream . toString ( ) , e . getMessage ( ) ) ) ; } }
runs a command line task and returns the screen output or throws and error if something bad happened
