code: def __init__(self, process: subprocess.Popen, detach: bool = False):
      self.process = process
      self.detach = detach
      self.task_id = None  # type: Optional[str]
  
      if self.detach:
          iterator = iter(self.process.stdout)  # type: ignore
          line = next(iterator)
          self.task_id = line.decode().strip()
      else:
          iterator = iter(self.process.stdout)  # type: ignore
          m = None
          max_iterations = 2
          iterations = 0
          while not m and iterations < max_iterations:
              line = next(iterator)
              iterations += 1
              m = re.search(rb"Launched .* \(id: (.*)\)", line)
          assert m is not None
          self.task_id = m.group(1).decode() if m else None
  
file_path: determined/e2e_tests/tests/command/command.py
imports: import os
  import re
  import subprocess
  from contextlib import contextmanager
  from typing import IO, Any, Iterator, Optional
  import requests
  from determined.common import api
  from determined.common.api import authentication, certs, task_logs
  from tests import api_utils
  from tests import config
label_desc: Use image node_id 1 to create a new _InteractiveCommandProcess object  with example: obj = _InteractiveCommandProcess(process, detach)