[{"data":1,"prerenderedAt":433},["ShallowReactive",2],{"node-red-\u002Fnode-red\u002Fcore-nodes\u002Fexec":3},{"id":4,"title":5,"body":6,"description":425,"extension":426,"meta":427,"navigation":428,"path":429,"seo":430,"stem":431,"__hash__":432},"nodeRed\u002Fnode-red\u002Fcore-nodes\u002Fexec.md","Node-RED - Exec Node",{"type":7,"value":8,"toc":411},"minimark",[9,14,30,35,48,55,70,76,80,90,100,106,109,113,131,135,138,143],[10,11,13],"h1",{"id":12},"exec","Exec",[15,16,17,18,25,26,29],"p",{},"Node-RED is written in Javascript, as are the custom nodes in the\n",[19,20,24],"a",{"href":21,"rel":22},"https:\u002F\u002Fflows.nodered.org\u002Fsearch?type=node",[23],"nofollow","Flows Library",". At times it would\nbe great to use programs written in other languages. In this guide we'll explain\nthe ",[27,28,12],"code",{}," node.",[31,32,34],"h3",{"id":33},"exec-node","Exec Node",[15,36,37,38,40,41,43,44,47],{},"Node-RED by default comes with the ",[27,39,12],{}," node. This node allows you to run a\ncommand as if you're on the command line. The exec node has one input, and three\noutputs. Let's create a basic example and work from there. Let's connect the\ninject to the ",[27,42,12],{}," input, and connect the three dots to debug nodes. I've set\nthe command in the exec node to ",[27,45,46],{},"date",".",[15,49,50],{},[51,52],"img",{"alt":53,"src":54},"\"Wired up exec node\"","\u002Fnode-red\u002Fcore-nodes\u002Fimages\u002Fwired-up-exec-node.png",[15,56,57,58,61,62,65,66,69],{},"When triggered, you'll see two outputs in the debug pane. One from ",[27,59,60],{},"Standard out",";\nthe date and timestamp of the execution and the ",[27,63,64],{},"Exit code"," will output too.\n",[27,67,68],{},"Standard error"," didn't output anything.",[15,71,72,73,75],{},"Let's explain what happened: the ",[27,74,46],{}," command was executed by the NodeJS without\nany input. The command returned the date as a string, and execution of the commmand\ncompleted. There weren't any errors, so the error code is set to zero. Non-zero\nexit codes imply didn't go as intended. Output is written to the standard output,\nand not standard error. This allows us to handle errors differently from succesful\nexections and the output in standard output.",[31,77,79],{"id":78},"exec-vs-spawn-mode","Exec vs Spawn mode",[15,81,82,83,85,86,89],{},"Let's change the ",[27,84,12],{}," node to execute ",[27,87,88],{},"ping google.com",". The ping command\nprovides the round-trip time to google.com in milliseconds, each second. When\nwe deploy, the program is stuck. That's because the output is generated each\nsecond and won't complete until there's a failure in the command. Not what you'd\nwant.",[15,91,92,93,96,97,99],{},"When there's continous output you'll need to select ",[27,94,95],{},"spawn"," mode in the settings\nwindown of the ",[27,98,12],{}," node:",[15,101,102],{},[51,103],{"alt":104,"src":105},"spawn mode for exec in Node-RED","\u002Fnode-red\u002Fcore-nodes\u002Fimages\u002Fspawn-mode-exec.png",[15,107,108],{},"This will produce a message per line to the standard out output for further\nprocessing.",[31,110,112],{"id":111},"shell-expansions","Shell Expansions",[15,114,115,116,119,120,123,124,126,127,130],{},"As the arguments for the exec nodes are executed as is, shell expansions will\nnot work. For example when the exec command is ",[27,117,118],{},"rm -r \u002Fpath\u002Fto\u002Fdir\u002F*",", the ",[27,121,122],{},"*","\nwill not be expanded and Node-RED will try to remove the file or directory called ",[27,125,122],{}," in the ",[27,128,129],{},"\u002Fpath\u002Fto\u002Fdir"," directory.",[31,132,134],{"id":133},"flowfuse","FlowFuse",[15,136,137],{},"On FlowFuse Cloud, the Node-RED exec nodes are disabled. The Stacks, that is the\ncontainers that Node-RED runs in, don't include any accessible executatables so there would be no benefit to running exec commands. All the data is exposed through Javascript and Node.JS already.",[139,140,142],"h2",{"id":141},"node-documentation","Node Documentation",[144,145,148,151,152,151,155,151,158,151,162,151,204,151,208,151,287,151,291,151,300,151,308,151,321,151,327,151,333,151,347,151,353,151,360,151,365,151,390,151,397,151,404],"div",{"className":146},[147],"core-node-doc",[15,149,150],{},"Runs a system command and returns its output."," ",[15,153,154],{},"The node can be configured to either wait until the command completes, or to\nsend its output as the command generates it.",[15,156,157],{},"The command that is run can be configured in the node or provided by the received\nmessage.",[31,159,161],{"id":160},"inputs","Inputs",[163,164,167,179,183,190,193,201],"dl",{"className":165},[166],"message-properties",[168,169,172,173],"dt",{"className":170},[171],"optional","payload ",[174,175,178],"span",{"className":176},[177],"property-type","string",[180,181,182],"dd",{},"if configured to do so, will be appended to the executed command.",[168,184,186,187],{"className":185},[171],"kill ",[174,188,178],{"className":189},[177],[180,191,192],{},"the type of kill signal to send an existing exec node process.",[168,194,196,197],{"className":195},[171],"pid ",[174,198,200],{"className":199},[177],"number|string",[180,202,203],{},"the process ID of an existing exec node process to kill.",[31,205,207],{"id":206},"outputs","Outputs",[209,210,213,241,265],"ol",{"className":211},[212],"node-ports",[214,215,216,217,228],"li",{},"Standard output\n",[163,218,220,225],{"className":219},[166],[168,221,172,222],{},[174,223,178],{"className":224},[177],[180,226,227],{},"the standard output of the command.",[163,229,231,238],{"className":230},[166],[168,232,233,234],{},"rc ",[174,235,237],{"className":236},[177],"object",[180,239,240],{},"exec mode only, a copy of the return code object (also available on port 3)",[214,242,243,244,255],{},"Standard error\n",[163,245,247,252],{"className":246},[166],[168,248,172,249],{},[174,250,178],{"className":251},[177],[180,253,254],{},"the standard error of the command.",[163,256,258,263],{"className":257},[166],[168,259,233,260],{},[174,261,237],{"className":262},[177],[180,264,240],{},[214,266,267,268],{},"Return code\n",[163,269,271,276],{"className":270},[166],[168,272,172,273],{},[174,274,237],{"className":275},[177],[180,277,278,279,282,283,286],{},"an object containing the return code, and possibly ",[27,280,281],{},"message",", ",[27,284,285],{},"signal"," properties.",[31,288,290],{"id":289},"details","Details",[15,292,293,294,296,297,47],{},"By default uses the ",[27,295,12],{}," system call which calls the command, waits for it to complete, and then\nreturns the output. For example a successful command should have a return code of ",[27,298,299],{},"{ code: 0 }",[15,301,302,303,305,306,47],{},"Optionally can use ",[27,304,95],{}," instead, which returns the output from stdout and stderr\nas the command runs, usually one line at a time. On completion it then returns an object\non the 3rd port. For example, a successful command should return ",[27,307,299],{},[15,309,310,311,314,315,317,318,320],{},"Errors may return extra information on the 3rd port ",[27,312,313],{},"msg.payload",", such as a ",[27,316,281],{}," string,\n",[27,319,285],{}," string.",[15,322,323,324,326],{},"The command that is run is defined within the node, with an option to append ",[27,325,313],{}," and a further set of parameters.",[15,328,329,330],{},"Commands or parameters with spaces should be enclosed in quotes - ",[27,331,332],{},"\"This is a single parameter\"",[15,334,335,336,339,340,343,344,47],{},"The returned ",[27,337,338],{},"payload"," is usually a ",[341,342,178],"i",{},", unless non-UTF8 characters are detected, in which\ncase it is a ",[341,345,346],{},"buffer",[15,348,349,350,29],{},"The node's status icon and PID will be visible while the node is active. Changes to this can be read by the ",[27,351,352],{},"Status",[15,354,355,356,359],{},"The ",[27,357,358],{},"Hide console"," option will hide the process console normally shown on Windows systems.",[361,362,364],"h4",{"id":363},"killing-processes","Killing processes",[15,366,367,368,371,372,374,375,282,378,381,382,385,386,389],{},"Sending ",[27,369,370],{},"msg.kill"," will kill a single active process. ",[27,373,370],{}," should be a string containing\nthe type of signal to be sent, for example, ",[27,376,377],{},"SIGINT",[27,379,380],{},"SIGQUIT"," or ",[27,383,384],{},"SIGHUP",".\nDefaults to ",[27,387,388],{},"SIGTERM"," if set to an empty string.",[15,391,392,393,396],{},"If the node has more than one process running then ",[27,394,395],{},"msg.pid"," must also be set with the value of the PID to be killed.",[15,398,399,400,403],{},"If a value is provided in the ",[27,401,402],{},"Timeout"," field then, if the process has not completed when the specified number of seconds has elapsed, the process will be killed automatically",[15,405,406,407,410],{},"Tip: if running a Python app you may need to use the ",[27,408,409],{},"-u"," parameter to stop the output being buffered.",{"title":412,"searchDepth":413,"depth":413,"links":414},"",2,[415,417,418,419,420],{"id":33,"depth":416,"text":34},3,{"id":78,"depth":416,"text":79},{"id":111,"depth":416,"text":112},{"id":133,"depth":416,"text":134},{"id":141,"depth":413,"text":142,"children":421},[422,423,424],{"id":160,"depth":416,"text":161},{"id":206,"depth":416,"text":207},{"id":289,"depth":416,"text":290},"Node-RED is written in Javascript, as are the custom nodes in the\nFlows Library. At times it would\nbe great to use programs written in other languages. In this guide we'll explain\nthe exec node.","md",{},true,"\u002Fnode-red\u002Fcore-nodes\u002Fexec",{"title":5,"description":425},"node-red\u002Fcore-nodes\u002Fexec","MxAztehEoPNp3bqbgwPAZuX5KY7XGDvF0gA8zBRlKhs",1780070555797]