Class CommandExec

java.lang.Object
com.pnfsoftware.jeb.util.concurrent.CommandExec

public class CommandExec extends Object
An object to allow the execution of external commands with timeout.
  • Constructor Details

    • CommandExec

      public CommandExec(long timeout)
      Create an object with an optional timeout.
      Parameters:
      timeout - timeout in milliseconds
      • positive: target will be killed when timeout has ellapsed
      • zero: no timeout (blocking execution)
      • negative: asynchronous execution, execute will always return true
  • Method Details

    • getOutput

      public byte[] getOutput()
      Get the command output. There might be some output present even when the command was prematurely stopped because a timeout elapsed.
      Returns:
    • execute

      public boolean execute(Collection<String> cmdlist)
      {@inheritDoc #execute(String...)}
    • execute

      public boolean execute(String... cmdarray)
      Execute a command. If execution takes more than the timeout provided at construction time, the executing process will be killed.
      Parameters:
      cmdarray - the command tokens (command and arguments), eg: ["ls", "-l", "*.java"]
      Returns:
      true if the command successfully completed, false if it timed'out