Class Shell


  • public final class Shell
    extends java.lang.Object
    Utility functions for use with execution of shell commands.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Shell.Encoding
      Singleton identifying the Charset used for encoding/decoding interactions with the "shell" command interpreter environment.
      static class  Shell.Result
      The execute(Charset, String...) command execution result.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static boolean IS_WINDOWS  
      private static org.slf4j.Logger LOGGER  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Shell()
      Private niladic constructor to prevent instantiation.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Shell.Result execute​(java.nio.charset.Charset consoleEncoding, java.lang.String... command)
      Executes a command in the host and returns the command output, both stdout and stderr, as a list of strings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • IS_WINDOWS

        private static final boolean IS_WINDOWS
    • Constructor Detail

      • Shell

        private Shell()
        Private niladic constructor to prevent instantiation.
    • Method Detail

      • execute

        public static Shell.Result execute​(java.nio.charset.Charset consoleEncoding,
                                           java.lang.String... command)
                                    throws java.io.IOException
        Executes a command in the host and returns the command output, both stdout and stderr, as a list of strings. This method blocks until the command is complete and its output consumed.
        Parameters:
        consoleEncoding - the Charset to use for decoding the command response
        command - the command to execute; this command is presented to ProcessBuilder.command() and must be properly quoted for the OS
        Returns:
        the command result
        Throws:
        java.io.IOException - if an error is raised while executing the command or retrieving the results