Execute Command Plus

Executes a command on the host

Overview

This node executes a shell command on the host machine where n8n is running. It allows users to run any command-line instruction and capture its output, error messages, and exit code. This is useful for integrating system-level operations or scripts into an automation workflow.

Common scenarios include:

  • Running custom scripts or commands that interact with local files or services.
  • Executing diagnostic commands and capturing their output for logging or decision-making.
  • Automating deployment or maintenance tasks by invoking CLI tools.

For example, you could use this node to run echo "Hello World" and capture the output, or execute a script that processes data and returns results to be used in subsequent workflow steps.

Properties

Name Meaning
Execute Once Whether to run the command only once (using the first input item) or once per each item.
Encoding The character encoding used to decode the command's output and error streams.
Command The shell command to execute. Can be multiline.

Output

The node outputs an array of items, each containing a JSON object with the following fields:

  • exitCode: The numeric exit code returned by the executed command (0 usually means success).
  • stdout: The standard output text produced by the command, decoded using the specified encoding.
  • stderr: The standard error text produced by the command, decoded using the specified encoding.
  • error (optional): If the command execution failed or an error occurred, this field contains the error message.

If multiple input items are processed (when "Execute Once" is false), the output items correspond one-to-one with the inputs, preserving pairing information.

The node does not produce binary data output.

Dependencies

  • Requires access to the host system's shell environment to execute commands.
  • Uses the iconv-lite library to decode command output according to the specified encoding.
  • No external API keys or online services are required.
  • The node runs commands with the permissions of the user running the n8n process.

Troubleshooting

  • Unrecognized encoding error: If the specified encoding is invalid or unsupported, the node throws an error indicating the encoding is not recognized. Ensure the encoding name matches those supported by the underlying decoding library.
  • Command execution errors: If the command fails (non-zero exit code or runtime error), the node captures the error message. Check the stderr output for details.
  • Permission issues: Commands may fail if the n8n process lacks necessary permissions to execute them or access resources.
  • Security caution: Avoid executing untrusted commands as this can lead to security risks or system compromise.
  • Empty output: If the command produces no output, stdout and stderr will be empty strings.

To handle errors gracefully, enable the node’s "Continue On Fail" option to allow workflows to proceed even if some commands fail.

Links and References

Discussion