org.appng.tools.os

## Class Command

- java.lang.Object
- - org.appng.tools.os.Command

-     public class Command
      extends Object

  Utility class to conveniently execute command via `Runtime.exec(String)`.
  Author:
    Matthias Müller

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `Command.StreamConsumer<T>` Interface for a type consuming and `InputStream`.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `ERROR`
    `static int` | `WRONG_OS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Command()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `execute(OperatingSystem os, String command, Command.StreamConsumer<?> outputConsumer, Command.StreamConsumer<?> errorConsumer)` Executes the given command, but only if the given `OperatingSystem` matches.
    `static int` | `execute(String command, Command.StreamConsumer<?> outputConsumer, Command.StreamConsumer<?> errorConsumer)` Executes the given command.

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

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

- - ### Field Detail

    - #### ERROR

          public static final int ERROR

      See Also:
        Constant Field Values

    - #### WRONG_OS

          public static final int WRONG_OS

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Command

          public Command()

  - ### Method Detail

    - #### execute

          public static int execute(String command,
                                    Command.StreamConsumer<?> outputConsumer,
                                    Command.StreamConsumer<?> errorConsumer)

      Executes the given command.
      Parameters:
        `command` - the command to execute
        `outputConsumer` - a `Command.StreamConsumer` to consume `Process.getInputStream()`
        `errorConsumer` - a `Command.StreamConsumer` to consume `Process.getErrorStream()`
      Returns:
        the value returned by `Process.waitFor()`, or -1 if an exception occurred while executing the process.

    - #### execute

          public static int execute(OperatingSystem os,
                                    String command,
                                    Command.StreamConsumer<?> outputConsumer,
                                    Command.StreamConsumer<?> errorConsumer)

      Executes the given command, but only if the given `OperatingSystem` matches.
      Parameters:
        `os` - the target `OperatingSystem`
        `command` - the command to execute
        `outputConsumer` - a `Command.StreamConsumer` to consume `Process.getInputStream()`
        `errorConsumer` - a `Command.StreamConsumer` to consume `Process.getErrorStream()`
      Returns:
        the return value of `execute(String, StreamConsumer, StreamConsumer)`, if the current `OperatingSystem` matches the desired one, otherwise -2
      See Also:
        `execute(String, StreamConsumer, StreamConsumer)`

Copyright © 2011–2023 aiticon GmbH. All rights reserved.