{"modulePath":"github.com/dracory/nodebase","version":"v0.7.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package exec\n\nPackage exec contains the exec node implementation.\n\n## Types\n\n```go\ntype ExecConfig struct {\n\t// Command is the base command line (trimmed). In buffered mode it\n\t// runs through the shell; in spawn mode it is split into argv.\n\tCommand string `json:\"command\"`\n\t// AddPay is the Node-RED \"append msg.X\" field: boolean true means\n\t// \"msg.payload\", a string names another message property, and\n\t// false/absent appends nothing. It is normalized into\n\t// ExecNode.addpayProp at construction.\n\tAddPay interface{} `json:\"addpay\"`\n\t// Append holds extra arguments appended after the addpay value\n\t// (trimmed).\n\tAppend string `json:\"append\"`\n\t// UseSpawn selects spawn mode (stream stdout/stderr chunks to the\n\t// first two outputs as they arrive). Node-RED serializes it as the\n\t// string \"true\"/\"false\" — DecodeConfig coerces.\n\tUseSpawn bool `json:\"useSpawn\"`\n\t// Timer is a kill timeout in seconds (0 = no timeout).\n\tTimer float64 `json:\"timer\"`\n\t// OldRC selects the legacy third-output payload: the bare exit\n\t// code instead of the {code:...} object. In buffered mode a\n\t// successful run then emits nothing on the third output\n\t// (Node-RED parity).\n\tOldRC bool `json:\"oldrc\"`\n}\n```\nExecConfig holds configuration for the exec node — the Node-RED \\`exec\\` equivalent.\n\n```go\ntype ExecNode struct {\n\t*nodebase.BaseNode\n\t// contains filtered or unexported fields\n}\n```\nExecNode runs a system command — the Node-RED \\`exec\\` node.\n\nOutputs (Node-RED wiring order):\n\n  - output\\_1: stdout (a message per chunk in spawn mode, the whole buffer in exec mode)\n  - output\\_2: stderr (only emitted while the command produces stderr; spawn mode streams per chunk)\n  - 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).\n\nSECURITY: 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.\n\n```go\nfunc NewExecNode(node nodestore.NodeInterface, config *ExecConfig, host nodebase.NodeHost) *ExecNode\n```\nNewExecNode creates a new exec node\n\n```go\nfunc (n *ExecNode) Activate(ctx context.Context) error\n```\nActivate 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.\n\n```go\nfunc (n *ExecNode) Execute(ctx context.Context, input nodestore.MessageInterface) (nodestore.MessageInterface, error)\n```\nExecute 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.\n\n```go\nfunc (n *ExecNode) SelectPorts(input, output nodestore.MessageInterface) []string\n```\nSelectPorts always routes the returned stdout message to output\\_1 — the stderr and return-code messages are emitted separately on their own ports.\n\n```go\nfunc (n *ExecNode) Stop() error\n```\nStop implements nodebase.Stopper: kill every child process this node still has running (Node-RED kills activeProcesses on close).\n\n```go\nfunc (n *ExecNode) StopKey() string\n```\nStopKey dedupes stopper registration across the per-message executor shells of one node.\n\n```go\nfunc (n *ExecNode) Validate() error\n```\nValidate checks the exec node configuration\n\n","path":"github.com/dracory/nodebase/exec","name":"exec","synopsis":"Package exec contains the exec node implementation.","isRedistributable":true}
