Class CommandInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
ecmwf.common.technical.CommandInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public final class CommandInputStream extends FilterInputStream implements AutoCloseable
A stream that connects an InputStream to the input of an external process, and allows reading the output produced by the process. This class manages the lifecycle of the associated process and its input/output streams, and handles stderr asynchronously to avoid potential deadlocks.
  • Constructor Details

    • CommandInputStream

      public CommandInputStream(InputStream in, Process process) throws IOException
      Creates a CommandInputStream that connects the given InputStream to the standard input of a process, and allows reading the standard output of that process.
      Parameters:
      in - The InputStream from which to send data to the process's input.
      process - The process to execute and communicate with.
      Throws:
      IOException - If any I/O error occurs during setup.
    • CommandInputStream

      public CommandInputStream(InputStream in, String[] command) throws IOException
      Creates a CommandInputStream by executing the given command.
      Parameters:
      in - The InputStream to send to the process's stdin.
      command - The command to run.
      Throws:
      IOException - If an error occurs while launching the process.
  • Method Details