跳到主要内容

Execute Command 节点常见问题

本页介绍 Execute Command 节点的常见错误和问题,以及解决或排查步骤。

Command failed: <command> /bin/sh: <command>: not found(命令失败:找不到命令) ​

shell 环境找不到 Command(命令)参数中的某条命令时,会出现此错误。

请检查以下内容:

  • Command(命令)参数中的命令及参数是否存在拼写错误。
  • 命令是否位于运行 n8n 的用户的 PATH 中。
  • 如果使用 Docker 运行 n8n,尝试在容器内手动运行命令,检查其是否可用。容器未包含所需命令时,可能需要基于官方 n8n 镜像创建包含该命令的自定义镜像。
    • n8n 已运行时:

      # Find n8n's container ID, it will be the first column
      docker ps | grep n8n
      # Try to execute the command within the running container
      docker container exec <container_ID> <command_to_run>
    • n8n 未运行时:

      # Start up a new container that runs the command instead of n8n
      # Use the same image and tag that you use to run n8n normally
      docker run -it --rm --entrypoint /bin/sh n8nio/n8n -c <command_to_run>

Error: stdout maxBuffer length exceeded(标准输出超过最大缓冲区长度) ​

命令返回的输出超过 Execute Command 节点单次能够处理的数量时,会出现此错误。

减少命令输出可以避免此错误。查看命令手册或文档,确认是否有用于限制或筛选输出的参数。如果没有,可能需要通过管道将输出传给其他命令,去掉不需要的信息。

PowerShell 命令在换行处被截断 ​

在 Windows 上,Execute Command 节点将 Command(命令)参数作为单个字符串传给系统 shell。命令中包含换行时,shell 只执行第一行,并忽略其余行。

这是 Windows shell 的限制,底层 cmd.exe 进程将每个换行视为命令结束。

将 PowerShell 命令写在单行中可以解决此问题。命令较复杂时,用分号连接各条语句:

powershell -Command "Get-ChildItem C:\Data; Write-Output 'Done'"

对于较长的脚本,将其保存为文件,再使用 -File 参数运行:

powershell -File C:\Scripts\my-script.ps1
本文为社区中文翻译。查看对应英文原文