org.apache.storm.utils

## Class ShellUtils.ShellCommandExecutor

- java.lang.Object
- - org.apache.storm.utils.ShellUtils
  - - org.apache.storm.utils.ShellUtils.ShellCommandExecutor

- Enclosing class:
    ShellUtils

      public static class ShellUtils.ShellCommandExecutor
      extends ShellUtils

  A simple shell command executor.

  `ShellCommandExecutor`should be used in cases where the output of the command needs no explicit parsing and where the command, working directory and the environment remains unchanged. The output of the command is stored as-is and is expected to be small.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.storm.utils.ShellUtils

      `ShellUtils.ExitCodeException, ShellUtils.OSType, ShellUtils.ShellCommandExecutor`

  - ### Field Summary

    - ### Fields inherited from class org.apache.storm.utils.ShellUtils

      `FREEBSD, LINUX, LOG, MAC, numShellExceptions, osType, OTHER, SOLARIS, timeOutInterval, TOKEN_SEPARATOR_REGEX, WINDOWS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ShellCommandExecutor(String[] execString)`
    `ShellCommandExecutor(String[] execString, File dir)`
    `ShellCommandExecutor(String[] execString, File dir, Map<String,String> env)`
    `ShellCommandExecutor(String[] execString, File dir, Map<String,String> env, long timeout)` Create a new instance of the ShellCommandExecutor to execute a command.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `execute()` Execute the shell command.
    `String[]` | `getExecString()` return an array containing the command name & its parameters.
    `String` | `getOutput()` Get the output of the shell command.
    `protected void` | `parseExecResult(BufferedReader lines)` Parse the execution result.
    `String` | `toString()` Returns the commands of this instance.

    - ### Methods inherited from class org.apache.storm.utils.ShellUtils

      `getExitCode, getGroupsCommand, getGroupsForUserCommand, getLogHandler, getProcess, isTimedOut, run, setEnvironment, setWorkingDirectory`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ShellCommandExecutor

          public ShellCommandExecutor(String[] execString)

    - #### ShellCommandExecutor

          public ShellCommandExecutor(String[] execString,
                                      File dir)

    - #### ShellCommandExecutor

          public ShellCommandExecutor(String[] execString,
                                      File dir,
                                      Map<String,String> env)

    - #### ShellCommandExecutor

          public ShellCommandExecutor(String[] execString,
                                      File dir,
                                      Map<String,String> env,
                                      long timeout)

      Create a new instance of the ShellCommandExecutor to execute a command.

      Parameters:
        `execString` - The command to execute with arguments
        `dir` - If not-null, specifies the directory which should be set as the current working directory for the command. If null, the current working directory is not modified.
        `env` - If not-null, environment of the command will include the key-value pairs specified in the map. If null, the current environment is not modified.
        `timeout` - Specifies the time in milliseconds, after which the command will be killed and the status marked as timedout. If 0, the command will not be timed out.

  - ### Method Detail

    - #### execute

          public void execute()
                       throws IOException

      Execute the shell command.

      Throws:
        `IOException`

    - #### getExecString

          public String[] getExecString()

      Description copied from class: `ShellUtils`

      return an array containing the command name & its parameters.

      Specified by:
        `getExecString` in class `ShellUtils`

    - #### parseExecResult

          protected void parseExecResult(BufferedReader lines)
                                  throws IOException

      Description copied from class: `ShellUtils`

      Parse the execution result.

      Specified by:
        `parseExecResult` in class `ShellUtils`
      Throws:
        `IOException`

    - #### getOutput

          public String getOutput()

      Get the output of the shell command.

    - #### toString

          public String toString()

      Returns the commands of this instance. Arguments with spaces in are presented with quotes round; other arguments are presented raw

      Overrides:
        `toString` in class `Object`
      Returns:
        a string representation of the object.

Copyright © 2019 The Apache Software Foundation. All rights reserved.