Package gw.util

Class Shell


  • @Deprecated
    public class Shell
    extends java.lang.Object
    Deprecated.
    use ProcessRunner instead
    • Constructor Summary

      Constructors 
      Constructor Description
      Shell()
      Deprecated.
       
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static ProcessStarter buildProcess​(java.lang.String command)
      Deprecated.
      Builds a process starter given a command.
      static void dumpStacks()
      Deprecated.
       
      static java.lang.String exec​(java.lang.String command)
      Deprecated.
      Executes the given command as if it had been executed from the command line of the host OS (cmd.exe on windows, /bin/sh on *nix) and returns all content sent to standard out as a string.
      static java.lang.String exec​(java.lang.String command, java.lang.String cs)
      Deprecated.
      Executes the given command as if it had been executed from the command line of the host OS (cmd.exe on windows, /bin/sh on *nix) and returns all content sent to standard out as a string.
      void execWithPipe​(java.lang.String command)
      Deprecated.
      Executes the given command as if it had been executed from the command line of the host OS (cmd.exe on windows, /bin/sh on *nix) and pipes all data sent to this processes stdout, stderr, and stdin.
      static java.lang.String getAllThreadStacks()
      Deprecated.
       
      static OSPlatform.Platform getPlatform()
      Deprecated.
      static boolean isLinux()
      Deprecated.
      static boolean isMac()
      Deprecated.
      use OSPlatform.isMac() instead
      static boolean isSolaris()
      Deprecated.
      static boolean isWindows()
      Deprecated.
      static java.lang.String readLine​(java.lang.String prompt)
      Deprecated.
      Prints the given prompt and then reads a line from standard in.
      static java.lang.String readMaskedLine​(java.lang.String prompt)
      Deprecated.
      Prints the given prompt and then reads a line from standard in, but with the input masked with asterisks
      • Methods inherited from class java.lang.Object

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

      • Shell

        public Shell()
        Deprecated.
    • Method Detail

      • exec

        public static java.lang.String exec​(java.lang.String command)
        Deprecated.

        Executes the given command as if it had been executed from the command line of the host OS (cmd.exe on windows, /bin/sh on *nix) and returns all content sent to standard out as a string. If the command finishes with a non zero return value, a CommandFailedException is thrown.

        Content sent to standard error by the command will be forwarded to standard error for this JVM. If you wish to capture StdErr as well, use buildProcess(String) to create a ProcessStarter and call the ProcessStarter.withStdErrHandler(gw.util.ProcessStarter.OutputHandler) method.

        This method blocks on the execution of the command.

        Example Usages:

           var currentDir = Shell.exec( "dir" ) // windows
           var currentDir = Shell.exec( "ls" )  // *nix
           Shell.exec( "rm -rf " + directoryToNuke )
         

        Parameters:
        command - the command to execute
        Returns:
        the content of standard out
        Throws:
        CommandFailedException - if the process finishes with a non-zero return value

        Note: On windows, CMD.EXE will be used to interpret "command" so that commands like "dir" work as expected. This can occasionally cause problems due to limitations of CMD.EXE (e.g. a command string may be too long for it.) In these cases consider using the buildProcess(String)

      • exec

        public static java.lang.String exec​(java.lang.String command,
                                            java.lang.String cs)
        Deprecated.

        Executes the given command as if it had been executed from the command line of the host OS (cmd.exe on windows, /bin/sh on *nix) and returns all content sent to standard out as a string. If the command finishes with a non zero return value, a CommandFailedException is thrown.

        Content sent to standard error by the command will be forwarded to standard error for this JVM. If you wish to capture StdErr as well, use buildProcess(String) to create a ProcessStarter and call the ProcessStarter.withStdErrHandler(gw.util.ProcessStarter.OutputHandler) method.

        This method blocks on the execution of the command.

        Example Usages:

           var currentDir = Shell.exec( "dir" ) // windows
           var currentDir = Shell.exec( "ls" )  // *nix
           Shell.exec( "rm -rf " + directoryToNuke )
         

        Parameters:
        command - the command to execute
        Returns:
        the content of standard out
        Throws:
        CommandFailedException - if the process finishes with a non-zero return value

        Note: On windows, CMD.EXE will be used to interpret "command" so that commands like "dir" work as expected. This can occasionally cause problems due to limitations of CMD.EXE (e.g. a command string may be too long for it.) In these cases consider using the buildProcess(String)

      • execWithPipe

        public void execWithPipe​(java.lang.String command)
        Deprecated.

        Executes the given command as if it had been executed from the command line of the host OS (cmd.exe on windows, /bin/sh on *nix) and pipes all data sent to this processes stdout, stderr, and stdin. If the command finishes with a non zero return value, a CommandFailedException is thrown.

        Stdout and Stderr from the sub-process will be piped to the current process' stdout and stderr. Any input in this processes stdin will be piped to the sub-process' stdin

        Content sent to standard error by the command will be forwarded to standard error for this JVM.

        This method blocks on the execution of the command.

        Example Usages:

           Shell.exec( "read \"are you there?\"" )
         

        Parameters:
        command - the command to execute
        Throws:
        CommandFailedException - if the process finishes with a non-zero return value
      • buildProcess

        public static ProcessStarter buildProcess​(java.lang.String command)
        Deprecated.
        Builds a process starter given a command. Single parameters in the command can be grouped by using double quotes or single quotes. I.e. ls "~/my file with spaces" works as well as ls '~/my file with spaces'.
        Parameters:
        command - the command to create a process starter for
        Returns:
        the process start.
      • isMac

        @Deprecated
        public static boolean isMac()
        Deprecated.
        use OSPlatform.isMac() instead
      • isLinux

        @Deprecated
        public static boolean isLinux()
        Deprecated.
      • readLine

        public static java.lang.String readLine​(java.lang.String prompt)
        Deprecated.
        Prints the given prompt and then reads a line from standard in. This can be used for basic user interactions in command line environments. This method uses the JLine library to provide a reasonable line-editing experience for the user. For example, the delete key, arrow keys, and home and end keys work as they would expect, and the prompt is not editable.
        Parameters:
        prompt - the prompt to show the user
        Returns:
        the string entered
      • readMaskedLine

        public static java.lang.String readMaskedLine​(java.lang.String prompt)
        Deprecated.
        Prints the given prompt and then reads a line from standard in, but with the input masked with asterisks
        Parameters:
        prompt - the prompt to show the user
        Returns:
        the string entered
      • getAllThreadStacks

        public static java.lang.String getAllThreadStacks()
        Deprecated.
      • dumpStacks

        public static void dumpStacks()
        Deprecated.