Class Shell

java.lang.Object
gmbh.pagina.tools.gradle.mac_app.Shell

public class Shell extends Object
An object to interact with the system shell.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    The exit code of the shell call.
    final String
    The shell output, stdout and stderr.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static Shell
    failOk(String... command)
    Execute a shell command but do not throw on a non-zero exit code.
    Return the output lines of the message.
    boolean
    Has the shell terminated correctly with a normal exit code.
    protected static Shell
    sh(String... command)
    Execute a shell command.
    protected static Shell
    shInDir(File workingDirectory, String... command)
    Execute a shell command in a specific working directory.
    protected static boolean
    test(String... command)
    Test whether a shell command is successful.

    Methods inherited from class java.lang.Object

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

    • out

      public final String out
      The shell output, stdout and stderr.
    • exitcode

      public final int exitcode
      The exit code of the shell call.
  • Method Details

    • isOk

      public boolean isOk()
      Has the shell terminated correctly with a normal exit code.
      Returns:
      true when the process exit code is zero.
    • getLines

      public String[] getLines()
      Return the output lines of the message.
      Returns:
      output split by line separator.
    • test

      protected static boolean test(String... command)
      Test whether a shell command is successful. Long output is truncated.
      Parameters:
      command - Command and arguments.
      Returns:
      true when the command exits with code zero.
    • failOk

      protected static Shell failOk(String... command)
      Execute a shell command but do not throw on a non-zero exit code.
      Parameters:
      command - Command and arguments.
      Returns:
      Shell result including output and exit code.
    • sh

      protected static Shell sh(String... command)
      Execute a shell command.
      Parameters:
      command - Command and arguments.
      Returns:
      Shell result including output and exit code.
    • shInDir

      protected static Shell shInDir(File workingDirectory, String... command)
      Execute a shell command in a specific working directory.
      Parameters:
      workingDirectory - Working directory used for command execution.
      command - Command and arguments.
      Returns:
      Shell result including output and exit code.