org.linkedin.util-core/src/main/java/org/linkedin/util/concurrent/ExternalCommand.java
public static ExternalCommand executeWithTimeout(File workingDirectory,
                                                   String command,
                                                   long timeout,
                                                   String... args)
      throws IOException, InterruptedException, TimeoutException
  {
    List<String> arguments = new ArrayList<String>(args.length + 1);

    arguments.add(new File(workingDirectory, command).getAbsolutePath());
    arguments.addAll(Arrays.asList(args));

    ExternalCommand cmd = ExternalCommand.create(arguments);

    cmd.setWorkingDirectory(workingDirectory);

    cmd.setRedirectErrorStream(true);

    cmd.start();

    /* Use timeout if it is a valid value! */
    if (timeout <= 0)
      cmd.waitFor();
    else
      cmd.waitFor(timeout);

    if (log.isDebugEnabled())
      log.debug(cmd.getStringOutput());

    return cmd;
  }
public static ExternalCommand executeWithTimeout(File workingDirectory,
                                                   String command,
                                                   long timeout,
                                                   String... args)
      throws IOException, InterruptedException, TimeoutException
  {
    List<String> arguments = new ArrayList<String>(args.length + 1);

    arguments.add(new File(workingDirectory, command).getAbsolutePath());
    arguments.addAll(Arrays.asList(args));

    ExternalCommand cmd = ExternalCommand.create(arguments);

    cmd.setWorkingDirectory(workingDirectory);

    cmd.setRedirectErrorStream(true);

    cmd.start();

    /* Use timeout if it is a valid value! */
    if (timeout <= 0)
      cmd.waitFor();
    else
      cmd.waitFor(timeout);

    if (log.isDebugEnabled())
      log.debug(cmd.getStringOutput());

    return cmd;
  }
public static ExternalCommand executeWithTimeout ( File workingDirectory , String command , long timeout , String ... args ) throws IOException , InterruptedException , TimeoutException { List < String > arguments = new ArrayList < String > ( args . length + 1 ) ; arguments . add ( new File ( workingDirectory , command ) . getAbsolutePath ( ) ) ; arguments . addAll ( Arrays . asList ( args ) ) ; ExternalCommand cmd = ExternalCommand . create ( arguments ) ; cmd . setWorkingDirectory ( workingDirectory ) ; cmd . setRedirectErrorStream ( true ) ; cmd . start ( ) ; /* Use timeout if it is a valid value! */ if ( timeout <= 0 ) cmd . waitFor ( ) ; else cmd . waitFor ( timeout ) ; if ( log . isDebugEnabled ( ) ) log . debug ( cmd . getStringOutput ( ) ) ; return cmd ; }
Executes the external command in the given working directory and waits (until timeout
is elapsed) for it to be finished.

@param workingDirectory
the root directory from where to run the command
@param command
the command to execute (should be relative to the working directory
@param timeout
the maximum amount of time to wait for this external command (in ms). If
this value is less than or equal to 0, timeout is ignored
@param args
the arguments to the command
@return the process
Executes the external command in the given working directory and waits ( until timeout is elapsed ) for it to be finished .