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)[source]¶

Wrapper class 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.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.

__init__(strip_newlines: bool = False, return_err_output: bool = False, persistent: bool = False)[source]¶

Initializes with default settings

process_output(output: str, command: str) str[source]¶

Uses regex to remove the command from the output

Parameters
  • output – a process’ output string

  • command – the executed command

run(commands: Union[str, List[str]]) str[source]¶

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

Examples using BashProcess¶