exec

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package exec contains the exec node implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecConfig

type ExecConfig struct {
	// Command is the base command line (trimmed). In buffered mode it
	// runs through the shell; in spawn mode it is split into argv.
	Command string `json:"command"`
	// AddPay is the Node-RED "append msg.X" field: boolean true means
	// "msg.payload", a string names another message property, and
	// false/absent appends nothing. It is normalized into
	// ExecNode.addpayProp at construction.
	AddPay interface{} `json:"addpay"`
	// Append holds extra arguments appended after the addpay value
	// (trimmed).
	Append string `json:"append"`
	// UseSpawn selects spawn mode (stream stdout/stderr chunks to the
	// first two outputs as they arrive). Node-RED serializes it as the
	// string "true"/"false" — DecodeConfig coerces.
	UseSpawn bool `json:"useSpawn"`
	// Timer is a kill timeout in seconds (0 = no timeout).
	Timer float64 `json:"timer"`
	// OldRC selects the legacy third-output payload: the bare exit
	// code instead of the {code:...} object. In buffered mode a
	// successful run then emits nothing on the third output
	// (Node-RED parity).
	OldRC bool `json:"oldrc"`
}

ExecConfig holds configuration for the exec node — the Node-RED `exec` equivalent.

type ExecNode

type ExecNode struct {
	*nodebase.BaseNode
	// contains filtered or unexported fields
}

ExecNode runs a system command — the Node-RED `exec` node.

Outputs (Node-RED wiring order):

  • output_1: stdout (a message per chunk in spawn mode, the whole buffer in exec mode)
  • output_2: stderr (only emitted while the command produces stderr; spawn mode streams per chunk)
  • output_3: the return code — {code:N} / {code:null,signal:...} / {code:N,message:"Command failed: ..."} unless oldrc, which emits the bare code (and in buffered mode nothing on success).

SECURITY: arbitrary command execution is gated behind NodeHost.ExecAllowed() — the node fails with "exec disabled" unless the flag is set (the consuming application wires it in main). The addpay value is concatenated into the command line exactly like Node-RED does, so even an enabled exec node is only as safe as the messages routed into it.

func NewExecNode

func NewExecNode(node nodestore.NodeInterface, config *ExecConfig, host nodebase.NodeHost) *ExecNode

NewExecNode creates a new exec node

func (*ExecNode) Activate added in v0.7.0

func (n *ExecNode) Activate(ctx context.Context) error

Activate implements nodebase.Activator: the exec node is a Stopper (it must kill spawned children on undeploy) but activation is not a message run — it only resolves the shared process registry so Stop() can reach it later.

func (*ExecNode) Execute

Execute handles a message: a "kill" property signals the active process(es) and produces no output; otherwise the command runs — buffered through the shell (exec mode) or as a streamed spawn.

func (*ExecNode) SelectPorts

func (n *ExecNode) SelectPorts(input, output nodestore.MessageInterface) []string

SelectPorts always routes the returned stdout message to output_1 — the stderr and return-code messages are emitted separately on their own ports.

func (*ExecNode) Stop added in v0.7.0

func (n *ExecNode) Stop() error

Stop implements nodebase.Stopper: kill every child process this node still has running (Node-RED kills activeProcesses on close).

func (*ExecNode) StopKey added in v0.7.0

func (n *ExecNode) StopKey() string

StopKey dedupes stopper registration across the per-message executor shells of one node.

func (*ExecNode) Validate

func (n *ExecNode) Validate() error

Validate checks the exec node configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL