public class

ExternalCommand

extends Object
java.lang.Object
   ↳ org.apache.helix.filestore.ExternalCommand

Summary

Fields
public static final Logger LOG
public static final String MODULE
Public Constructors
ExternalCommand(ProcessBuilder processBuilder)
Constructor
Public Methods
static ExternalCommand create(List<String> commands)
Creates an external process from the command.
static ExternalCommand create(String... commands)
Creates an external process from the command.
void destroy()
static ExternalCommand execute(File workingDirectory, String command, String... args)
Executes the external command in the given working directory and waits for it to be finished.
static ExternalCommand executeWithTimeout(File workingDirectory, String command, long timeout, String... args)
Executes the external command in the given working directory and waits (until timeout is elapsed) for it to be finished.
int exitValue()
Map<StringString> getEnvironment()
byte[] getError()
byte[] getOutput()
boolean getRedirectErrorStream()
String getStringError(String encoding)
Returns the error as a string.
String getStringError()
Returns the error as a string.
String getStringOutput(String encoding)
Returns the output as a string.
String getStringOutput()
Returns the output as a string.
File getWorkingDirectory()
void setRedirectErrorStream(boolean redirectErrorStream)
void setWorkingDirectory(File directory)
void start()
After creating the command, you have to start it...
static ExternalCommand start(String... commands)
Creates an external process from the command.
int waitFor(long timeout)
Properly waits until everything is complete: joins on the thread that reads the output, joins on the thread that reads the error and finally wait for the process to be finished.
int waitFor()
Properly waits until everything is complete: joins on the thread that reads the output, joins on the thread that reads the error and finally wait for the process to be finished.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public static final Logger LOG

public static final String MODULE

Public Constructors

public ExternalCommand (ProcessBuilder processBuilder)

Constructor

Public Methods

public static ExternalCommand create (List<String> commands)

Creates an external process from the command. It is not started and you have to call start on it!

Parameters
commands the command to execute
Returns
  • the process

public static ExternalCommand create (String... commands)

Creates an external process from the command. It is not started and you have to call start on it!

Parameters
commands the command to execute
Returns
  • the process

public void destroy ()

public static ExternalCommand execute (File workingDirectory, String command, String... args)

Executes the external command in the given working directory and waits for it to be finished.

Parameters
workingDirectory the root directory from where to run the command
command the command to execute (should be relative to the working directory
args the arguments to the command
Returns
  • the process

public static ExternalCommand executeWithTimeout (File workingDirectory, String command, long timeout, String... args)

Executes the external command in the given working directory and waits (until timeout is elapsed) for it to be finished.

Parameters
workingDirectory the root directory from where to run the command
command the command to execute (should be relative to the working directory
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
args the arguments to the command
Returns
  • the process

public int exitValue ()

public Map<StringString> getEnvironment ()

See Also

public byte[] getError ()

public byte[] getOutput ()

public boolean getRedirectErrorStream ()

See Also

public String getStringError (String encoding)

Returns the error as a string.

Returns
  • error as string

public String getStringError ()

Returns the error as a string. Uses encoding "UTF-8".

Returns
  • error as string

public String getStringOutput (String encoding)

Returns the output as a string.

Returns
  • encoded string

public String getStringOutput ()

Returns the output as a string. Uses encoding "UTF-8".

Returns
  • utf8 encoded string

public File getWorkingDirectory ()

See Also

public void setRedirectErrorStream (boolean redirectErrorStream)

See Also

public void setWorkingDirectory (File directory)

See Also

public void start ()

After creating the command, you have to start it...

Throws
IOException

public static ExternalCommand start (String... commands)

Creates an external process from the command. The command is executed.

Parameters
commands the commands to execute
Returns
  • the process
Throws
IOException if there is an error

public int waitFor (long timeout)

Properly waits until everything is complete: joins on the thread that reads the output, joins on the thread that reads the error and finally wait for the process to be finished. If the process has not completed before the timeout, throws a TimeoutException

Returns
  • the status code of the process.
Throws
TimeoutException
InterruptedException
TimeoutException

public int waitFor ()

Properly waits until everything is complete: joins on the thread that reads the output, joins on the thread that reads the error and finally wait for the process to be finished.

Returns
  • the status code of the process.