How to run exec on the background?

Hi, I made a flow that monitors a device every 30s, executing curl commands to log in and retrieve the information from a web server in another device. (I couldn't do it with an HTTP request because I never could pass the authentification so any help with that will be good)

So, with the exec node, I send 2 Curl commands POST to log in and GET to retrieve the info

It works as intended, the only thing is that on my laptop it runs great, the Curl commands are executed in the background but when I exported the flow to a desktop that will be always running the exec node flash the CMD window every 30 s which could be annoying if someone else wants to use the computer.

so is there an option to make it running in the background? I don't know what could be the difference between my laptop and the desktop, the only thing that comes to my mind is that during the installation of node-red on my laptop I needed to install some dependencies manually like python, Microsoft visual studio community, and remove some windows updates that were messing around with my laptop

On the desktop, everything installed easily (both with win 10)

What are these devices? Do that have any other means of passing data (e.g. MQTT?)

Post your flow (obviously change password or any sensitive info)

1 Like

Thank you for the answer, I am thankfull that you are interested on the overall solution. I cant exchange data with the device because is not capable of that... Im login to the web server that is used to set up the device and scrapping the HTML information to retrive the status, so I do not think that the flow will be useful, by the other hand for the HTTP Request I found a lot of similar cases in the forum while triying to do the same and no answer to propperly do a log in with the HTTP Request Node.

The curlcommands work, maybe Im not ussing propperly the HTTP Request

[{"id":"dea3bc5a.4f1b5","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"f8f3e27a.49109","type":"debug","z":"dea3bc5a.4f1b5","name":"2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1130,"y":280,"wires":[]},{"id":"6314ef9c.b3bd","type":"exec","z":"dea3bc5a.4f1b5","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":430,"y":120,"wires":[["cafc69f9.52acf8","f497c2de.585ce"],[],[]]},{"id":"cafc69f9.52acf8","type":"debug","z":"dea3bc5a.4f1b5","name":"1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":80,"wires":[]},{"id":"810a8448.333628","type":"inject","z":"dea3bc5a.4f1b5","name":"1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"30","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":240,"wires":[["38fee3db.6ba97c"]]},{"id":"1b0f691b.902ca7","type":"inject","z":"dea3bc5a.4f1b5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"curl \"http://192.168.1.14/startpage\" ^   -H \"Connection: keep-alive\" ^   -H \"Upgrade-Insecure-Requests: 1\" ^   -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\" ^   -H \"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\" ^   -H \"Referer: http://192.168.1.14/login\" ^   -H \"Accept-Language: en-US,en;q=0.9,es;q=0.8\" ^   -H \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=E6947458A1EE60BC303638319A76B4D9CEDFFD4FB230E397B10C9651B5A85AFB; _csrf_token=EE61AF8E08779969BF68970C41B4033CC2CF8CB6645E7D490DA61ADFFE8FE390\" ","payloadType":"str","x":890,"y":600,"wires":[["3b340b6b.ce4554"]]},{"id":"e0c00efb.f40f5","type":"html","z":"dea3bc5a.4f1b5","name":"","property":"payload","outproperty":"payload","tag":".wg_output_text","ret":"html","as":"single","x":660,"y":280,"wires":[["524ed186.06ff5"]]},{"id":"524ed186.06ff5","type":"function","z":"dea3bc5a.4f1b5","name":"","func":"msg.payload=[msg.payload[1].split(\">\").pop(),\nmsg.payload[3].split(\">\").pop(),\nmsg.payload[5].split(\">\").pop(),\nmsg.payload[7].split(\">\").pop()];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":860,"y":280,"wires":[["f8f3e27a.49109","e3b777bf.b64a88"]]},{"id":"f497c2de.585ce","type":"timed-counter","z":"dea3bc5a.4f1b5","name":"","timelimit":"550","timeunit":1,"withhold":true,"fixedtimeout":false,"pertopic":false,"x":600,"y":160,"wires":[["b4cab213.eb8c3"]]},{"id":"b4cab213.eb8c3","type":"switch","z":"dea3bc5a.4f1b5","name":"","property":"count","propertyType":"msg","rules":[{"t":"eq","v":"2","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":640,"y":220,"wires":[["e0c00efb.f40f5"],[]]},{"id":"e3b777bf.b64a88","type":"switch","z":"dea3bc5a.4f1b5","name":"","property":"payload[1]","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1020,"y":420,"wires":[["53a57e5b.bb9f7"],["3b340b6b.ce4554"]]},{"id":"11dfc2f9.97d19d","type":"debug","z":"dea3bc5a.4f1b5","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1310,"y":320,"wires":[]},{"id":"53a57e5b.bb9f7","type":"change","z":"dea3bc5a.4f1b5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"H2 Generator running","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1160,"y":380,"wires":[["11dfc2f9.97d19d"]]},{"id":"e2b0e4bb.d90a18","type":"debug","z":"dea3bc5a.4f1b5","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1350,"y":440,"wires":[]},{"id":"3b340b6b.ce4554","type":"change","z":"dea3bc5a.4f1b5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"H2 DOWN!!!","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1200,"y":500,"wires":[["e2b0e4bb.d90a18","72034846.026938"]]},{"id":"72034846.026938","type":"e-mail","z":"dea3bc5a.4f1b5","server":"smtp.gmail.com","port":"465","secure":true,"tls":true,"name":"","dname":"","x":1330,"y":740,"wires":[]},{"id":"38fee3db.6ba97c","type":"trigger","z":"dea3bc5a.4f1b5","name":"","op1":"curl \"http://192.168.1.14/login\" ^   -H \"Connection: keep-alive\" ^   -H \"Cache-Control: max-age=0\" ^   -H \"Upgrade-Insecure-Requests: 1\" ^   -H \"Origin: http://192.168.1.14\" ^   -H \"Content-Type: application/x-www-form-urlencoded\" ^   -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\" ^   -H \"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\" ^   -H \"Referer: http://192.168.1.14/login\" ^   -H \"Accept-Language: en-US,en;q=0.9,es;q=0.8\" ^   -H \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=F214B7C88481BD2E11513D93C8ACDC525F48E8D17DEFD6FABD7FBB4040652669; _csrf_token=281B2EB2E5EDDFCC761ABEF5104605B37B2395E950B8DEF82886FBBFCF7ADE9D\"","op2":"curl \"http://192.168.1.14/moni_1\" ^   -H \"Connection: keep-alive\" ^   -H \"Upgrade-Insecure-Requests: 1\" ^   -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\" ^   -H \"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\" ^   -H \"Referer: http://192.168.1.14/startpage\" ^   -H \"Accept-Language: en-US,en;q=0.9,es;q=0.8\" ^   -H \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=A5E8EA2C3C713568143207F37E1F5A5C0661FF435D87A5B721812BF52944BD14; _csrf_token=E6EFF120396769EC3DB1EC39AF8F8539204A60DEA3F61747FF52E8DAA872D2E1\" ","op1type":"str","op2type":"str","duration":"500","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":280,"y":240,"wires":[["6314ef9c.b3bd"]]},{"id":"e1ffd333.f12b4","type":"catch","z":"dea3bc5a.4f1b5","name":"","scope":["524ed186.06ff5"],"uncaught":false,"x":350,"y":740,"wires":[["94597bdc.9ebd78"]]},{"id":"7b71dbb.76bc524","type":"change","z":"dea3bc5a.4f1b5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Connection lost","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"Connection to H2 generator lost","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":740,"wires":[["72034846.026938"]]},{"id":"94597bdc.9ebd78","type":"trigger","z":"dea3bc5a.4f1b5","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"0","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":580,"y":740,"wires":[["7b71dbb.76bc524"]]},{"id":"9c47d8f6.97e5a8","type":"inject","z":"dea3bc5a.4f1b5","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"reset","payloadType":"str","x":330,"y":620,"wires":[["94597bdc.9ebd78"]]}]

[post edited to add ``` before and after code paste]

Windows is notorious at creating command prompt windows that flash up and then disappear. I get that every time I restart Node-RED on my dev PC.

How are you running Node-RED on the desktop? You may be able to mess around with how it is run and that might fix it.

There are several other alternatives though if the desktop is up to running virtualised environments. You could either use Docker for Windows or you could use the Windows Subsystem for Linux (WSL). Both of these will provide different, more Linux-like environments and will avoid any Windows terminal issues.

Try this...

[{"id":"f8f3e27a.49109","type":"debug","z":"dea3bc5a.4f1b5","name":"2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":280,"wires":[]},{"id":"810a8448.333628","type":"inject","z":"dea3bc5a.4f1b5","name":"1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"30","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":60,"wires":[["faae4202.374b3"]]},{"id":"1b0f691b.902ca7","type":"inject","z":"dea3bc5a.4f1b5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"curl \"http://192.168.1.14/startpage\" ^   -H \"Connection: keep-alive\" ^   -H \"Upgrade-Insecure-Requests: 1\" ^   -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\" ^   -H \"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\" ^   -H \"Referer: http://192.168.1.14/login\" ^   -H \"Accept-Language: en-US,en;q=0.9,es;q=0.8\" ^   -H \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=E6947458A1EE60BC303638319A76B4D9CEDFFD4FB230E397B10C9651B5A85AFB; _csrf_token=EE61AF8E08779969BF68970C41B4033CC2CF8CB6645E7D490DA61ADFFE8FE390\" ","payloadType":"str","x":390,"y":440,"wires":[["3b340b6b.ce4554"]]},{"id":"e0c00efb.f40f5","type":"html","z":"dea3bc5a.4f1b5","name":"","property":"payload","outproperty":"payload","tag":".wg_output_text","ret":"html","as":"single","x":280,"y":280,"wires":[["524ed186.06ff5"]]},{"id":"524ed186.06ff5","type":"function","z":"dea3bc5a.4f1b5","name":"","func":"msg.payload=[msg.payload[1].split(\">\").pop(),\nmsg.payload[3].split(\">\").pop(),\nmsg.payload[5].split(\">\").pop(),\nmsg.payload[7].split(\">\").pop()];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":280,"wires":[["f8f3e27a.49109","e3b777bf.b64a88"]]},{"id":"e3b777bf.b64a88","type":"switch","z":"dea3bc5a.4f1b5","name":"","property":"payload[1]","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":380,"wires":[["53a57e5b.bb9f7"],["3b340b6b.ce4554"]]},{"id":"11dfc2f9.97d19d","type":"debug","z":"dea3bc5a.4f1b5","name":"3a","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":360,"wires":[]},{"id":"53a57e5b.bb9f7","type":"change","z":"dea3bc5a.4f1b5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"H2 Generator running","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":360,"wires":[["11dfc2f9.97d19d"]]},{"id":"e2b0e4bb.d90a18","type":"debug","z":"dea3bc5a.4f1b5","name":"3b","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":400,"wires":[]},{"id":"3b340b6b.ce4554","type":"change","z":"dea3bc5a.4f1b5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"H2 DOWN!!!","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":400,"wires":[["e2b0e4bb.d90a18","72034846.026938"]]},{"id":"72034846.026938","type":"e-mail","z":"dea3bc5a.4f1b5","server":"smtp.gmail.com","port":"465","secure":true,"tls":true,"name":"","dname":"","x":770,"y":500,"wires":[]},{"id":"e1ffd333.f12b4","type":"catch","z":"dea3bc5a.4f1b5","name":"","scope":["524ed186.06ff5"],"uncaught":false,"x":150,"y":540,"wires":[["94597bdc.9ebd78"]]},{"id":"7b71dbb.76bc524","type":"change","z":"dea3bc5a.4f1b5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Connection lost","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"Connection to H2 generator lost","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":520,"wires":[["72034846.026938"]]},{"id":"94597bdc.9ebd78","type":"trigger","z":"dea3bc5a.4f1b5","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"0","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":380,"y":520,"wires":[["7b71dbb.76bc524"]]},{"id":"9c47d8f6.97e5a8","type":"inject","z":"dea3bc5a.4f1b5","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"reset","payloadType":"str","x":150,"y":500,"wires":[["94597bdc.9ebd78"]]},{"id":"eb232072.660654","type":"debug","z":"dea3bc5a.4f1b5","name":"Req1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":140,"wires":[]},{"id":"a0d94d4a.3771e2","type":"function","z":"dea3bc5a.4f1b5","name":"Prepare request moni_1","func":"//original curl:  \n\n// curl \"http://192.168.1.14/moni_1\" \n// -H \"Connection: keep-alive\" \n// -H \"Upgrade-Insecure-Requests: 1\" \n// -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\" \n// -H \"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\" \n// -H \"Referer: http://192.168.1.14/startpage\" \n// -H \"Accept-Language: en-US,en;q=0.9,es;q=0.8\" \n// -H \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=A5E8EA2C3C713568143207F37E1F5A5C0661FF435D87A5B721812BF52944BD14; _csrf_token=E6EFF120396769EC3DB1EC39AF8F8539204A60DEA3F61747FF52E8DAA872D2E1\" \n\nmsg = {\n    ip: msg.ip\n}; //make new msg object (removes previous http request items)\n\nmsg.url = `http://${msg.ip}/moni_1`;\nmsg.payload = \"\";\nmsg.headers = {\n    \"Connection\": \"keep-alive\",\n    \"Upgrade-Insecure-Requests\": \"1\",\n    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\",\n    \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\",\n    \"Referer\": `http://${msg.ip}/startpage`,\n    \"Accept-Language\": \"en-US,en;q=0.9,es;q=0.8\"\n};\nmsg.cookies = {\n    \"uibuilder-namespace\": \"elogbooks\",\n    \"io\": \"-6M-3lcOPxxQ4NxEAAAL\",\n    \"upd_state\": \"off\",\n    \"siemens_ad_session\": \"A5E8EA2C3C713568143207F37E1F5A5C0661FF435D87A5B721812BF52944BD14\",\n    \"_csrf_token\": \"E6EFF120396769EC3DB1EC39AF8F8539204A60DEA3F61747FF52E8DAA872D2E1\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":210,"y":200,"wires":[["a0d94d4a.3771e3"]]},{"id":"a0d94d4a.3771e3","type":"http request","z":"dea3bc5a.4f1b5","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":410,"y":200,"wires":[["a0d94d4a.3771e4","e0c00efb.f40f5"]]},{"id":"a0d94d4a.3771e4","type":"debug","z":"dea3bc5a.4f1b5","name":"Req2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":200,"wires":[]},{"id":"faae4202.374b3","type":"change","z":"dea3bc5a.4f1b5","name":"set msg.ip = 192.168.1.14","rules":[{"t":"set","p":"ip","pt":"msg","to":"192.168.1.14","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":60,"wires":[["eb232072.660652"]]},{"id":"eb232072.660652","type":"function","z":"dea3bc5a.4f1b5","name":"Prepare request /login","func":"// original curl:  curl \"http://192.168.1.14/login\"\n// -H \"Connection: keep-alive\"\n// -H \"Cache-Control: max-age=0\"\n// -H \"Upgrade-Insecure-Requests: 1\"\n// -H \"Origin: http://192.168.1.14\"\n// -H \"Content-Type: application/x-www-form-urlencoded\"\n// -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\"\n// -H \"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*; q = 0.8, application / signed - exchange; v = b3; q = 0.9\"\n// - H \"Referer: http://192.168.1.14/login\"\n// - H \"Accept-Language: en-US,en;q=0.9,es;q=0.8\"\n// - H \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=F214B7C88481BD2E11513D93C8ACDC525F48E8D17DEFD6FABD7FBB4040652669; _csrf_token=281B2EB2E5EDDFCC761ABEF5104605B37B2395E950B8DEF82886FBBFCF7ADE9D\"\n\nmsg.url = \"http://192.168.1.14/login\";\nmsg.payload = \"\";\nmsg.headers = {\n    \"Connection\": \"keep-alive\",\n    \"Cache-Control\": \"max-age=0\",\n    \"Upgrade-Insecure-Requests\": \"1\",\n    \"Origin\": \"http://192.168.1.14\",\n    \"Content-Type\": \"application/x-www-form-urlencoded\",\n    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\",\n    \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\",\n    \"Referer\": msg.url,\n    \"Accept-Language\": \"en-US,en;q=0.9,es;q=0.8\"\n};\nmsg.cookies = {\n    \"uibuilder-namespace\": \"elogbooks\",\n    \"io\": \"-6M-3lcOPxxQ4NxEAAAL\",\n    \"upd_state\": \"off\",\n    \"siemens_ad_session\": \"F214B7C88481BD2E11513D93C8ACDC525F48E8D17DEFD6FABD7FBB4040652669\",\n    \"_csrf_token\": \"281B2EB2E5EDDFCC761ABEF5104605B37B2395E950B8DEF82886FBBFCF7ADE9D\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":200,"y":140,"wires":[["eb232072.660653"]]},{"id":"eb232072.660653","type":"http request","z":"dea3bc5a.4f1b5","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":410,"y":140,"wires":[["eb232072.660654","a0d94d4a.3771e2"]]}]

NOTE...
You probably need to capture the cookies from the 1st REQ and use the in the function to build the 2nd request
(currently you have a hard coded cookie that will likely expire)

This is not an immediate solution, but possibly a way to treat the problem.

According to the docs, there is a special parameter used in exec that should hide a cmd window on windows system. windowsHide Hide the subprocess console window that would normally be created on Windows systems. Default: false added in nodejs v8.8

An enhancement to the exec node might be needed to pass that value to child_process.exec.

Thanks but it didn't work, I dont understand why thats really the same idea that i had since the begining but never could make it to work.I also understand that I should take the cookies from the 1st REQ but dont know how.

The first and the second Node returns Error 500: Server Error
Bad request.

I used new hardcoded cookies, and of course this was tested on the original node and it is working with the exec, any ideas?

by the way triying to autentificate using the log in user and password directly on the HTTP request Node does not work either, I can't pass the login page but at least I got a response with the HTML

Thanks for the idea, right now I think that it is beyond my understanding how to pass that propperty to exec, but I will check it out

Looking at that HideWindow option - Can anyone think why it would be a good idea to not hide it all the time anyway ? I'm surprised no-one mentioned it before - so is it actually useful ? What value does it really have to have windows popping up all the time ? Should we change that to be hidden for next release ?

1 Like

There are some folk who run node-red in current user space and actually want (need?) to see the child process (i.e. they fire up a gui app)

if it were to be added, i think as an option would be best Dave.

NOTE: if the op ran node-red as a service, he would not see the child processes popping up (thats how i do it on our WIN servers)

2 Likes

Strange, my demo added all the headers you had.

Can you try these 2 demos - show me what comes out of the debug nodes...

[{"id":"810a8448.333628","type":"inject","z":"553814a2.1248ec","name":"1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":650,"y":2580,"wires":[["faae4202.374b3"]]},{"id":"eb232072.660654","type":"debug","z":"553814a2.1248ec","name":"Req1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1270,"y":2660,"wires":[]},{"id":"a0d94d4a.3771e2","type":"function","z":"553814a2.1248ec","name":"Prepare request moni_1","func":"//original curl:  \n\n// curl \"http://192.168.1.14/moni_1\" \n// -H \"Connection: keep-alive\" \n// -H \"Upgrade-Insecure-Requests: 1\" \n// -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\" \n// -H \"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\" \n// -H \"Referer: http://192.168.1.14/startpage\" \n// -H \"Accept-Language: en-US,en;q=0.9,es;q=0.8\" \n// -H \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=A5E8EA2C3C713568143207F37E1F5A5C0661FF435D87A5B721812BF52944BD14; _csrf_token=E6EFF120396769EC3DB1EC39AF8F8539204A60DEA3F61747FF52E8DAA872D2E1\" \n\nmsg = {\n    ip: msg.ip\n}; //make new msg object (removes previous http request items)\n\nmsg.url = `http://${msg.ip}/moni_1`;\nmsg.payload = \"\";\nmsg.headers = {\n    \"Connection\": \"keep-alive\",\n    \"Upgrade-Insecure-Requests\": \"1\",\n    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\",\n    \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\",\n    \"Referer\": `http://${msg.ip}/startpage`,\n    \"Accept-Language\": \"en-US,en;q=0.9,es;q=0.8\",\n    \"Cookie\": \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=A5E8EA2C3C713568143207F37E1F5A5C0661FF435D87A5B721812BF52944BD14; _csrf_token=E6EFF120396769EC3DB1EC39AF8F8539204A60DEA3F61747FF52E8DAA872D2E1\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":2720,"wires":[["a0d94d4a.3771e3"]]},{"id":"a0d94d4a.3771e3","type":"http request","z":"553814a2.1248ec","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":910,"y":2720,"wires":[["a0d94d4a.3771e4"]]},{"id":"a0d94d4a.3771e4","type":"debug","z":"553814a2.1248ec","name":"Req2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1270,"y":2720,"wires":[]},{"id":"faae4202.374b3","type":"change","z":"553814a2.1248ec","name":"set msg.ip = 192.168.1.14","rules":[{"t":"set","p":"ip","pt":"msg","to":"192.168.1.14","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":2580,"wires":[["eb232072.660652"]]},{"id":"eb232072.660652","type":"function","z":"553814a2.1248ec","name":"Prepare request /login","func":"// original curl:  curl \"http://192.168.1.14/login\"\n// -H \"Connection: keep-alive\"\n// -H \"Cache-Control: max-age=0\"\n// -H \"Upgrade-Insecure-Requests: 1\"\n// -H \"Origin: http://192.168.1.14\"\n// -H \"Content-Type: application/x-www-form-urlencoded\"\n// -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\"\n// -H \"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*; q = 0.8, application / signed - exchange; v = b3; q = 0.9\"\n// - H \"Referer: http://192.168.1.14/login\"\n// - H \"Accept-Language: en-US,en;q=0.9,es;q=0.8\"\n// - H \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=F214B7C88481BD2E11513D93C8ACDC525F48E8D17DEFD6FABD7FBB4040652669; _csrf_token=281B2EB2E5EDDFCC761ABEF5104605B37B2395E950B8DEF82886FBBFCF7ADE9D\"\n\nmsg.url = \"http://192.168.1.14/login\";\nmsg.payload = \"\";\nmsg.headers = {\n    \"Connection\": \"keep-alive\",\n    \"Cache-Control\": \"max-age=0\",\n    \"Upgrade-Insecure-Requests\": \"1\",\n    \"Origin\": \"http://192.168.1.14\",\n    \"Content-Type\": \"application/x-www-form-urlencoded\",\n    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\",\n    \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\",\n    \"Referer\": msg.url,\n    \"Accept-Language\": \"en-US,en;q=0.9,es;q=0.8\",\n    \"Cookie\": \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=F214B7C88481BD2E11513D93C8ACDC525F48E8D17DEFD6FABD7FBB4040652669; _csrf_token=281B2EB2E5EDDFCC761ABEF5104605B37B2395E950B8DEF82886FBBFCF7ADE9D\",\n};\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":2660,"wires":[["eb232072.660653"]]},{"id":"eb232072.660653","type":"http request","z":"553814a2.1248ec","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":910,"y":2660,"wires":[["eb232072.660654","a0d94d4a.3771e2"]]},{"id":"f8a1f287.65b67","type":"comment","z":"553814a2.1248ec","name":"test 1","info":"","x":650,"y":2540,"wires":[]},{"id":"b093949f.bcdbc8","type":"inject","z":"553814a2.1248ec","name":"2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":650,"y":2860,"wires":[["4b9d63a8.8465dc"]]},{"id":"331ab2f7.77517e","type":"debug","z":"553814a2.1248ec","name":"Req3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1270,"y":2940,"wires":[]},{"id":"9d58183e.05a718","type":"function","z":"553814a2.1248ec","name":"Prepare request moni_1","func":"//original curl:  \n\n// curl \"http://192.168.1.14/moni_1\" \n// -H \"Connection: keep-alive\" \n// -H \"Upgrade-Insecure-Requests: 1\" \n// -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\" \n// -H \"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\" \n// -H \"Referer: http://192.168.1.14/startpage\" \n// -H \"Accept-Language: en-US,en;q=0.9,es;q=0.8\" \n// -H \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=A5E8EA2C3C713568143207F37E1F5A5C0661FF435D87A5B721812BF52944BD14; _csrf_token=E6EFF120396769EC3DB1EC39AF8F8539204A60DEA3F61747FF52E8DAA872D2E1\" \n\nmsg = {\n    ip: msg.ip\n}; //make new msg object (removes previous http request items)\n\nmsg.url = `http://${msg.ip}/moni_1`;\nmsg.payload = \"\";\nmsg.headers = {\n    \"Connection\": \"keep-alive\",\n    \"Upgrade-Insecure-Requests\": \"1\",\n    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\",\n    \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\",\n    \"Referer\": `http://${msg.ip}/startpage`,\n    \"Accept-Language\": \"en-US,en;q=0.9,es;q=0.8\",\n    \"Cookie\": \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=A5E8EA2C3C713568143207F37E1F5A5C0661FF435D87A5B721812BF52944BD14; _csrf_token=E6EFF120396769EC3DB1EC39AF8F8539204A60DEA3F61747FF52E8DAA872D2E1\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":3000,"wires":[["aeca4401.62a948"]]},{"id":"aeca4401.62a948","type":"http request","z":"553814a2.1248ec","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":910,"y":3000,"wires":[["70fc3c87.6bf674"]]},{"id":"70fc3c87.6bf674","type":"debug","z":"553814a2.1248ec","name":"Req4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1270,"y":3000,"wires":[]},{"id":"ea246833.791758","type":"function","z":"553814a2.1248ec","name":"Prepare request /login","func":"// original curl:  curl \"http://192.168.1.14/login\"\n// -H \"Connection: keep-alive\"\n// -H \"Cache-Control: max-age=0\"\n// -H \"Upgrade-Insecure-Requests: 1\"\n// -H \"Origin: http://192.168.1.14\"\n// -H \"Content-Type: application/x-www-form-urlencoded\"\n// -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\"\n// -H \"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*; q = 0.8, application / signed - exchange; v = b3; q = 0.9\"\n// - H \"Referer: http://192.168.1.14/login\"\n// - H \"Accept-Language: en-US,en;q=0.9,es;q=0.8\"\n// - H \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=F214B7C88481BD2E11513D93C8ACDC525F48E8D17DEFD6FABD7FBB4040652669; _csrf_token=281B2EB2E5EDDFCC761ABEF5104605B37B2395E950B8DEF82886FBBFCF7ADE9D\"\n\nmsg.url = `http://${msg.user}:${msg.pass}@192.168.1.14/login`;\nmsg.payload = \"\";\nmsg.headers = {\n    \"Connection\": \"keep-alive\",\n    \"Cache-Control\": \"max-age=0\",\n    \"Upgrade-Insecure-Requests\": \"1\",\n    \"Origin\": \"http://192.168.1.14\",\n    \"Content-Type\": \"application/x-www-form-urlencoded\",\n    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51\",\n    \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\",\n    \"Referer\": \"http://192.168.1.14/login\",\n    \"Accept-Language\": \"en-US,en;q=0.9,es;q=0.8\",\n    \"Cookie\": \"Cookie: uibuilder-namespace=elogbooks; io=-6M-3lcOPxxQ4NxEAAAL; upd_state=off; siemens_ad_session=F214B7C88481BD2E11513D93C8ACDC525F48E8D17DEFD6FABD7FBB4040652669; _csrf_token=281B2EB2E5EDDFCC761ABEF5104605B37B2395E950B8DEF82886FBBFCF7ADE9D\",\n};\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":2940,"wires":[["3b75dea5.34ef82"]]},{"id":"3b75dea5.34ef82","type":"http request","z":"553814a2.1248ec","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":910,"y":2940,"wires":[["331ab2f7.77517e","9d58183e.05a718"]]},{"id":"add9c6f9.6257c8","type":"comment","z":"553814a2.1248ec","name":"test 2 - this one needs you to enter  user   and   password in the change node","info":"","x":860,"y":2820,"wires":[]},{"id":"4b9d63a8.8465dc","type":"change","z":"553814a2.1248ec","name":"*** SET USER and PASSWORD HERE ***","rules":[{"t":"set","p":"ip","pt":"msg","to":"192.168.1.14","tot":"str"},{"t":"set","p":"user","pt":"msg","to":"USERNAME-SET-ME","tot":"str"},{"t":"set","p":"pass","pt":"msg","to":"PASSWORD-SET-ME","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":2860,"wires":[["ea246833.791758"]]}]

I think that the poping out problem is on the computer that is running as a service, on that computer I created a service to run node-red on startup, is that what you were referring to?

On my laptop, it does not pup up but I manually executing node-red to start

I think because it doesn't always happen. Or sometimes the new window is under everything else and so not really noticeable. The current windows default terminal can be a bit of an odd beast at times.

A way of making it more future-proof might be to allow the end user to set the exec options with an object. You could filter out the properties that you absolutely cannot allow and pass the rest to the child_process. That way you won't have to worry about handling the individual properties, but of course, it will make it easier for the end user to break things.

Well, just to give you an update I think I finally did what I wanted when I open the post, running the exec in the background. (Still executing the curl commands on EXEC node with a hardcoded cookie, that I had to renew every 2 to 3 days instead of a propper HTTP request with authentification but is better than don't being able to do it at all)

But for the exec part, seems that if the service is made to startup with pm2 and pm2 windows startup package, the exec part will be popping out every time, I replicated the conditions of the desktop in my laptop and indeed it was like that, so y proceeded to remove the service and this time I used nssm https://gist.github.com/dceejay/576b4847f0a17dc066db and now it is working in the background... at least it works in the laptop.

Later on, I will try on the desktop

2 Likes

Thanks for sharing, that is useful to know. I only do dev on Windows, I don't often run NR live on Windows. I do use PM2 and it does pop up a window whenever it restarts.

I couldnt do it on the desktop there is no C:\Users<user>\AppData\Roaming\npm\node-red.cmd file to auto start the service...

Edited just in case someone bumbs with this too
I found the cmd file at "C:\Program Files\nodejs\node-red.cmd"

Now is running as I wanted, at least for the EXEC.

Does anyone know how to use the http request nofr to login?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.