class_docstr: Execute subprocesses under the control of pexpect.
      
class_docstr_tok: ["Execute","subprocesses","under","the","control","of","pexpect","."]
docstr: Execute a command in a subshell.
  
  Parameters
  ----------
  cmd : str
    A command to be executed in the system shell.
  
  Returns
  -------
  int : child's exitstatus
docstr_tok: ["Execute","a","command","in","a","subshell",".","Parameters","--","--","--","--","--","cmd",":","str","A","command","to","be","executed","in","the","system","shell",".","Returns","--","--","--","-","int",":","child","'s","exitstatus"]
code: def system(self, cmd):
      """Execute a command in a subshell.
  
      Parameters
      ----------
      cmd : str
        A command to be executed in the system shell.
  
      Returns
      -------
      int : child's exitstatus
      """
      # Get likely encoding for the output.
      enc = DEFAULT_ENCODING
  
      # Patterns to match on the output, for pexpect.  We read input and
      # allow either a short timeout or EOF
      patterns = [pexpect.TIMEOUT, pexpect.EOF]
      # the index of the EOF pattern in the list.
      # even though we know it's 1, this call means we don't have to worry if
      # we change the above list, and forget to change this value:
      EOF_index = patterns.index(pexpect.EOF)
      # The size of the output stored so far in the process output buffer.
      # Since pexpect only appends to this buffer, each time we print we
      # record how far we've printed, so that next time we only print *new*
      # content from the buffer.
      out_size = 0
      try:
          # Since we're not really searching the buffer for text patterns, we
          # can set pexpect's search window to be tiny and it won't matter.
          # We only search for the 'patterns' timeout or EOF, which aren't in
          # the text itself.
          # child = pexpect.spawn(pcmd, searchwindowsize=1)
          if hasattr(pexpect, "spawnb"):
              child = pexpect.spawnb(
                  self.sh, args=["-c", cmd]
              )  # Pexpect-U
          else:
              child = pexpect.spawn(
                  self.sh, args=["-c", cmd]
              )  # Vanilla Pexpect
          flush = sys.stdout.flush
          while True:
              # res is the index of the pattern that caused the match, so we
              # know whether we've finished (if we matched EOF) or not
              res_idx = child.expect_list(patterns, self.read_timeout)
              print(
                  child.before[out_size:].decode(enc, "replace"), end=""
              )
              flush()
              if res_idx == EOF_index:
                  break
              # Update the pointer to what we've already printed
              out_size = len(child.before)
      except KeyboardInterrupt:
          # We need to send ^C to the process.  The ascii code for '^C' is 3
          # (the character is known as ETX for 'End of Text', see
          # curses.ascii.ETX).
          child.sendline(chr(3))
          # Read and print any more output the program might produce on its
          # way out.
          try:
              out_size = len(child.before)
              child.expect_list(patterns, self.terminate_timeout)
              print(
                  child.before[out_size:].decode(enc, "replace"), end=""
              )
              sys.stdout.flush()
          except KeyboardInterrupt:
              # Impatient users tend to type it multiple times
              pass
          finally:
              # Ensure the subprocess really is terminated
              child.terminate(force=True)
      # add isalive check, to ensure exitstatus is set:
      child.isalive()
  
      # We follow the subprocess pattern, returning either the exit status
      # as a positive number, or the terminating signal as a negative
      # number.
      # on Linux, sh returns 128+n for signals terminating child processes on Linux
      # on BSD (OS X), the signal code is set instead
      if child.exitstatus is None:
          # on WIFSIGNALED, pexpect sets signalstatus, leaving exitstatus=None
          if child.signalstatus is None:
              # this condition may never occur,
              # but let's be certain we always return an integer.
              return 0
          return -child.signalstatus
      if child.exitstatus > 128:
          return -(child.exitstatus - 128)
      return child.exitstatus
  
file_path: catboost/contrib/python/ipython/py2/IPython/utils/_process_posix.py
imports: from __future__ import print_function
  import errno
  import os
  import subprocess
  import sys
  import pexpect
  from ._process_common import getoutput, arg_split
  from IPython.utils import py3compat
  from IPython.utils.encoding import DEFAULT_ENCODING
label_desc: Use image node_id 5 for calling the ProcessHandler obj's underlying member method code with example usage: obj.system(cmd) and returns: child, unknown, unknown, int