public class


extends Object
   ↳ com.pnfsoftware.jeb.util.concurrent.CommandExec

Class Overview

An object to allow the execution of external commands with timeout.


Public Constructors
CommandExec(long timeout)
Create an object with an optional timeout.
Public Methods
boolean execute(String... cmdarray)
Execute a command.
boolean execute(Collection<String> cmdlist)
byte[] getOutput()
Get the command output.
Inherited Methods
From class java.lang.Object

Public Constructors

public CommandExec (long timeout)

Create an object with an optional timeout.

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

Public Methods

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.

cmdarray the command tokens (command and arguments), eg: ["ls", "-l", "*.java"]
  • true if the command successfully completed, false if it timed'out

public boolean execute (Collection<String> cmdlist)

public byte[] getOutput ()

Get the command output. There might be some output present even when the command was prematurely stopped because a timeout elapsed.