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]

包装器,用于启动子进程。

使用Python内置的subprocess.run() 在Windows系统上**不**支持持久进程,因为pexpect使用Unix伪终端(ptys)。MacOS和Linux可以。

示例: .. code-block:: python

from langchain_community.utilities.bash import BashProcess

bash = BashProcess(

strip_newlines = False, return_err_output = False, persistent = False

) bash.run(‘echo ‘hello world’’)

使用默认设置进行初始化

Attributes

persistent

是否生成持久会话 注意:不适用于Windows环境

return_err_output

是否返回失败命令的输出,或者只返回错误消息和堆栈跟踪

strip_newlines

是否在输出上运行.strip()函数

Methods

__init__([strip_newlines, ...])

使用默认设置进行初始化

process_output(output, command)

使用正则表达式从输出中删除命令

run(commands)

在现有的持久子进程中运行命令,或者在新的子进程环境中运行命令。

Parameters
  • strip_newlines (bool) –

  • return_err_output (bool) –

  • persistent (bool) –

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

使用默认设置进行初始化

Parameters
  • strip_newlines (bool) –

  • return_err_output (bool) –

  • persistent (bool) –

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

使用正则表达式从输出中删除命令

参数:

output: 进程的输出字符串 command: 执行的命令

Parameters
  • output (str) –

  • command (str) –

Return type

str

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

在现有的持久子进程中运行命令,或者在新的子进程环境中运行命令。

参数:

commands(List[str]): 要在会话中执行的命令列表

Parameters

commands (Union[str, List[str]]) –

Return type

str