public static void closeOnProcessTermination(@NotNull ProcessHandler processHandler, @NotNull Closeable closeable) {
    processHandler.addProcessListener(new ProcessListener() {
      @Override
      public void startNotified(@NotNull ProcessEvent event) {
        // Nothing.
      }

      @Override
      public void processTerminated(@NotNull ProcessEvent event) {
        try {
          closeable.close();
        }
        catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      }

      @Override
      public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
        // Nothing.
      }
    });
  }
public static void closeOnProcessTermination(@NotNull ProcessHandler processHandler, @NotNull Closeable closeable)