Toggle Menu
Prev Up Next

# `langchain_experimental.llm_bash.bash`.BashProcess

class langchain_experimental.llm_bash.bash.BashProcess(strip_newlines: bool = False, return_err_output: bool = False, persistent: bool = False)

  Wrapper for starting subprocesses.

  Uses the python built-in subprocesses.run() Persistent processes are not available on Windows systems, as pexpect makes use of Unix pseudoterminals (ptys). MacOS and Linux are okay.

  Example

      from langchain_community.utilities.bash import BashProcess

      bash = BashProcess(
          strip_newlines = False,
          return_err_output = False,
          persistent = False
      )
      bash.run('echo 'hello world'')

  Initializes with default settings

  Attributes

  `persistent` | Whether or not to spawn a persistent session NOTE: Unavailable for Windows environments
  `return_err_output` | Whether or not to return the output of a failed command, or just the error message and stacktrace
  `strip_newlines` | Whether or not to run .strip() on the output

  Methods

  `__init__`([strip_newlines, ...]) | Initializes with default settings
  `process_output`(output, command) | Uses regex to remove the command from the output
  `run`(commands) | Run commands in either an existing persistent subprocess or on in a new subprocess environment.

  Parameters

    - strip_newlines (bool) –

    - return_err_output (bool) –

    - persistent (bool) –

  __init__(strip_newlines: bool = False, return_err_output: bool = False, persistent: bool = False)

    Initializes with default settings

    Parameters

      - strip_newlines (bool) –

      - return_err_output (bool) –

      - persistent (bool) –

  process_output(output: str, command: str) → str

    Uses regex to remove the command from the output

    Parameters

      - output (str) – a process’ output string

      - command (str) – the executed command

    Return type

      str

  run(commands: Union[str, List[str]]) → str

    Run commands in either an existing persistent subprocess or on in a new subprocess environment.

    Parameters

      commands (List[str]) – a list of commands to execute in the session

    Return type

      str