parameters: (self, command, args=[], preexec_fn=None, dimensions=None)
docstring: This starts the given command in a child process. This does all the
          fork/exec type of stuff for a pty. This is called by __init__. If args
          is empty then command will be parsed (split on spaces) and args will be
          set to parsed arguments.
docstring_summary: This starts the given command in a child process. This does all the
          fork/exec type of stuff for a pty. This is called by __init__. If args
          is empty then command will be parsed (split on spaces) and args will be
          set to parsed arguments.
docstring_tokens: This starts the given command in a child process . This does all the fork / exec type of stuff for a pty . This is called by __init__ . If args is empty then command will be parsed ( split on spaces ) and args will be set to parsed arguments .
function: def _spawn(self, command, args=[], preexec_fn=None, dimensions=None):
          '''This starts the given command in a child process. This does all the
          fork/exec type of stuff for a pty. This is called by __init__. If args
          is empty then command will be parsed (split on spaces) and args will be
          set to parsed arguments. '''
  
          # The pid and child_fd of this object get set by this method.
          # Note that it is difficult for this method to fail.
          # You cannot detect if the child process cannot start.
          # So the only way you can tell if the child process started
          # or not is to try to read from the file descriptor. If you get
          # EOF immediately then it means that the child is already dead.
          # That may not necessarily be bad because you may have spawned a child
          # that performs some task; creates no stdout output; and then dies.
  
          # If command is an int type then it may represent a file descriptor.
          if isinstance(command, type(0)):
              raise ExceptionPexpect('Command is an int type. ' +
                      'If this is a file descriptor then maybe you want to ' +
                      'use fdpexpect.fdspawn which takes an existing ' +
                      'file descriptor instead of a command string.')
  
          if not isinstance(args, type([])):
              raise TypeError('The argument, args, must be a list.')
  
          if args == []:
              self.args = split_command_line(command)
              self.command = self.args[0]
          else:
              # Make a shallow copy of the args list.
              self.args = args[:]
              self.args.insert(0, command)
              self.command = command
  
          command_with_path = which(self.command, env=self.env)
          if command_with_path is None:
              raise ExceptionPexpect('The command was not found or was not ' +
                      'executable: %s.' % self.command)
          self.command = command_with_path
          self.args[0] = self.command
  
          self.name = '<' + ' '.join(self.args) + '>'
  
          assert self.pid is None, 'The pid member must be None.'
          assert self.command is not None, 'The command member must not be None.'
  
          kwargs = {'echo': self.echo, 'preexec_fn': preexec_fn}
          if self.ignore_sighup:
              def preexec_wrapper():
                  "Set SIGHUP to be ignored, then call the real preexec_fn"
                  signal.signal(signal.SIGHUP, signal.SIG_IGN)
                  if preexec_fn is not None:
                      preexec_fn()
              kwargs['preexec_fn'] = preexec_wrapper
  
          if dimensions is not None:
              kwargs['dimensions'] = dimensions
  
          if self.encoding is not None:
              # Encode command line using the specified encoding
              self.args = [a if isinstance(a, bytes) else a.encode(self.encoding)
                           for a in self.args]
  
          self.ptyproc = self._spawnpty(self.args, env=self.env,
                                       cwd=self.cwd, **kwargs)
  
          self.pid = self.ptyproc.pid
          self.child_fd = self.ptyproc.fd
  
  
          self.terminated = False
          self.closed = False
function_tokens: def _spawn ( self , command , args = [ ] , preexec_fn = None , dimensions = None ) : # The pid and child_fd of this object get set by this method. # Note that it is difficult for this method to fail. # You cannot detect if the child process cannot start. # So the only way you can tell if the child process started # or not is to try to read from the file descriptor. If you get # EOF immediately then it means that the child is already dead. # That may not necessarily be bad because you may have spawned a child # that performs some task; creates no stdout output; and then dies. # If command is an int type then it may represent a file descriptor. if isinstance ( command , type ( 0 ) ) : raise ExceptionPexpect ( 'Command is an int type. ' + 'If this is a file descriptor then maybe you want to ' + 'use fdpexpect.fdspawn which takes an existing ' + 'file descriptor instead of a command string.' ) if not isinstance ( args , type ( [ ] ) ) : raise TypeError ( 'The argument, args, must be a list.' ) if args == [ ] : self . args = split_command_line ( command ) self . command = self . args [ 0 ] else : # Make a shallow copy of the args list. self . args = args [ : ] self . args . insert ( 0 , command ) self . command = command command_with_path = which ( self . command , env = self . env ) if command_with_path is None : raise ExceptionPexpect ( 'The command was not found or was not ' + 'executable: %s.' % self . command ) self . command = command_with_path self . args [ 0 ] = self . command self . name = '<' + ' ' . join ( self . args ) + '>' assert self . pid is None , 'The pid member must be None.' assert self . command is not None , 'The command member must not be None.' kwargs = { 'echo' : self . echo , 'preexec_fn' : preexec_fn } if self . ignore_sighup : def preexec_wrapper ( ) : "Set SIGHUP to be ignored, then call the real preexec_fn" signal . signal ( signal . SIGHUP , signal . SIG_IGN ) if preexec_fn is not None : preexec_fn ( ) kwargs [ 'preexec_fn' ] = preexec_wrapper if dimensions is not None : kwargs [ 'dimensions' ] = dimensions if self . encoding is not None : # Encode command line using the specified encoding self . args = [ a if isinstance ( a , bytes ) else a . encode ( self . encoding ) for a in self . args ] self . ptyproc = self . _spawnpty ( self . args , env = self . env , cwd = self . cwd , * * kwargs ) self . pid = self . ptyproc . pid self . child_fd = self . ptyproc . fd self . terminated = False self . closed = False