Class InteractiveConsole

java.lang.Object
adalid.util.io.InteractiveConsole

public class InteractiveConsole extends Object
Utility class to attach the current console to a running Process, handling its output and error streams asynchronously while forwarding user input to the process. This version reads both stdout and stderr streams in separate threads to avoid blocking and ensures proper interaction with processes that use stderr for prompts or important messages.
Author:
Jorge Campins
  • Constructor Details

    • InteractiveConsole

      public InteractiveConsole()
  • Method Details

    • attachTo

      public static void attachTo(Process process)
      Attaches the current console to the given process. This method:
      • Starts separate threads to print process stdout and stderr.
      • Reads user input from System.in and sends it to process stdin.
      • Waits for the process to exit and for output threads to finish.
      Parameters:
      process - the Process to attach to