docs: def expect_output(self, pattern, timeout=-1):
          """Wait until the running program performs some given output, or terminates.
  
          Args:
              pattern:  The pattern the output should be checked for.
              timeout (int):  How many seconds should be waited for the output.
  
          The pattern argument may be a string, a compiled regular expression,
          or a list of any of those types. Strings will be compiled into regular expressions.
  
          Returns:
              int: The index into the pattern list. If the pattern was not a list, it returns 0 on a successful match.
  
          Raises:
              TimeoutException: The output did not match within the given time frame.
              TerminationException: The program terminated before producing the output.
              NestedException: An internal problem occured while waiting for the output.
          """
          logger.debug("Expecting output '{0}' from '{1}'".format(pattern, self.name))
          try:
              return self._spawn.expect(pattern, timeout)
          except pexpect.exceptions.EOF as e:
              logger.debug("Raising termination exception.")
              raise TerminationException(instance=self, real_exception=e, output=self.get_output())
          except pexpect.exceptions.TIMEOUT as e:
              logger.debug("Raising timeout exception.")
              raise TimeoutException(instance=self, real_exception=e, output=self.get_output())
          except Exception as e:
              logger.debug("Expecting output failed: " + str(e))
              raise NestedException(instance=self, real_exception=e, output=self.get_output())