code: def redirect_stream(system, target):
      
      if target is None:
          target_fd = os.open(os.devnull, os.O_RDWR)
      else:
          target_fd = target.fileno()
      try:
          os.dup2(target_fd, system.fileno())
      except OSError as err:
          raise DaemonError('Could not redirect {0} to {1}: {2}'
                            .format(system, target, err))
docs: Redirect Unix streams
  
      If None, redirect Stream to /dev/null, else redirect to target.
  
      :param system: ether sys.stdin, sys.stdout, or sys.stderr
      :type system: file object
  
      :param target: File like object, or None
      :type target: None, File Object
  
      :return: None
      :raise: DaemonError