code: def spawn(cls, argv, cwd=None, env=None, dimensions=(24, 80)):
          
          if isinstance(argv, str):
              argv = shlex.split(argv, posix=False)
  
          if not isinstance(argv, (list, tuple)):
              raise TypeError("Expected a list or tuple for argv, got %r" % argv)
  
          # Shallow copy of argv so we can modify it
          argv = argv[:]
          command = argv[0]
          env = env or os.environ
  
          path = env.get('PATH', os.defpath)
          command_with_path = which(command, path=path)
          if command_with_path is None:
              raise FileNotFoundError(
                  'The command was not found or was not ' +
                  'executable: %s.' % command
              )
          command = command_with_path
          argv[0] = command
          cmdline = ' ' + subprocess.list2cmdline(argv[1:])
          cwd = cwd or os.getcwd()
  
          proc = PTY(dimensions[1], dimensions[0])
  
          # Create the environemnt string.
          envStrs = []
          for (key, value) in env.items():
              envStrs.append('%s=%s' % (key, value))
          env = '\0'.join(envStrs) + '\0'
  
          if PY2:
              command = _unicode(command)
              cwd = _unicode(cwd)
              cmdline = _unicode(cmdline)
              env = _unicode(env)
  
          if len(argv) == 1:
              proc.spawn(command, cwd=cwd, env=env)
          else:
              proc.spawn(command, cwd=cwd, env=env, cmdline=cmdline)
  
          inst = cls(proc)
          inst._winsize = dimensions
  
          # Set some informational attributes
          inst.argv = argv
          if env is not None:
              inst.env = env
          if cwd is not None:
              inst.launch_dir = cwd
  
          return inst
docs: Start the given command in a child process in a pseudo terminal.
  
          This does all the setting up the pty, and returns an instance of
          PtyProcess.
  
          Dimensions of the psuedoterminal used for the subprocess can be
          specified as a tuple (rows, cols), or the default (24, 80) will be
          used.