Package alluxio.shell

Class ShellCommand

  • Direct Known Subclasses:
    ScpCommand, SshCommand

    @NotThreadSafe
    public class ShellCommand
    extends java.lang.Object
    Object representation of a shell command.
    • Constructor Summary

      Constructors 
      Constructor Description
      ShellCommand​(java.lang.String[] execString)
      Creates a ShellCommand object with the command to exec.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String[] getCommand()
      Gets the command.
      java.lang.String run()
      Runs a command and returns its stdout on success.
      CommandReturn runWithOutput()
      Runs a command and returns its output and exit code in Object.
      java.lang.String toString()
      Converts the command to string repr.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ShellCommand

        public ShellCommand​(java.lang.String[] execString)
        Creates a ShellCommand object with the command to exec.
        Parameters:
        execString - shell command
    • Method Detail

      • run

        public java.lang.String run()
                             throws java.io.IOException
        Runs a command and returns its stdout on success. Stderr is redirected to stdout.
        Returns:
        the output
        Throws:
        java.io.IOException - if the command returns a non-zero exit code
      • runWithOutput

        public CommandReturn runWithOutput()
                                    throws java.io.IOException
        Runs a command and returns its output and exit code in Object. Preserves the output when the execution fails. If the command execution fails (not by an interrupt), try to wrap the Exception in the CommandReturn. Stderr is redirected to stdout.
        Returns:
        CommandReturn object representation of stdout, stderr and exit code
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Converts the command to string repr.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the shell command
      • getCommand

        public java.lang.String[] getCommand()
        Gets the command. The original array is immutable.
        Returns:
        a copy of the command string array