public class

CommandExec

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

Class Overview

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

Summary

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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

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

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.

Parameters
cmdarray the command tokens (command and arguments), eg: ["ls", "-l", "*.java"]
Returns
  • 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.