Bash 自动化器

UFO 允许 HostAgent 在主机上执行 bash 命令。bash 命令可用于打开应用程序或执行系统命令。Bash 自动化器ufo/automator/app_apis/shell 模块中实现。

注意

Bash 自动化器目前仅支持 HostAgent

接收器

Web 自动化器接收器是 ufo/automator/app_apis/shell/shell_client.py 文件中定义的 ShellReceiver 类。

基类:ReceiverBasic

使用 crawl4ai 的 Web COM 客户端的基类。

初始化 shell 客户端。

源代码位于 automator/app_apis/shell/shell_client.py
19
20
21
22
def __init__(self) -> None:
    """
    Initialize the shell client.
    """

run_shell(params)

运行命令。

参数
  • params (Dict[str, Any]) –

    命令的参数。

返回
  • Any

    结果内容。

源代码位于 automator/app_apis/shell/shell_client.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def run_shell(self, params: Dict[str, Any]) -> Any:
    """
    Run the command.
    :param params: The parameters of the command.
    :return: The result content.
    """
    bash_command = params.get("command")
    powershell_path = 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'
    process = subprocess.Popen(
        bash_command,  # command to run
        stdout=subprocess.PIPE,  # capture stdout
        stderr=subprocess.PIPE,  # capture stderr
        shell=True,
        text=True,
        executable=powershell_path,
    )
    return ""


命令

我们目前在 Bash 自动化器中只支持一个命令来在主机上执行 bash 命令。

@ShellReceiver.register
class RunShellCommand(ShellCommand):
    """
    The command to run the crawler with various options.
    """

    def execute(self):
        """
        Execute the command to run the crawler.
        :return: The result content.
        """
        return self.receiver.run_shell(params=self.params)

    @classmethod
    def name(cls) -> str:
        """
        The name of the command.
        """
        return "run_shell"

下面是 UFO 目前支持的 Web 自动化器中可用的命令列表

命令名称 函数名称 描述
RunShellCommand run_shell 将网页内容转换为 markdown 格式。