Its posible open a program from node-red in Windows?

Is it possible to open a cmd terminal from node-Red on the local computer?
I wanted to open a program like ".exe" or ".jpg" from node-red. I don't know if I'm doing something wrong, but they start in the background according to the task manager

The following flow shows some tests but the images show the cmd in the background,


What's more, they don't close alone when changing the exec

[{"id":"e84603ae.338ce","type":"exec","z":"59ec00ab.cbf41","command":"start cmd","addpay":false,"append":"","useSpawn":"true","timer":"10","oldrc":false,"name":"","x":420,"y":140,"wires":[["a6c69679.389088"],["e1b9cd5e.9145f"],["d577fd24.3b93"]]},{"id":"a6c69679.389088","type":"debug","z":"59ec00ab.cbf41","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":670,"y":120,"wires":[]},{"id":"e1b9cd5e.9145f","type":"debug","z":"59ec00ab.cbf41","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":630,"y":140,"wires":[]},{"id":"d577fd24.3b93","type":"debug","z":"59ec00ab.cbf41","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":160,"wires":[]},{"id":"d84974f0.390708","type":"function","z":"59ec00ab.cbf41","name":"","func":"const cp = global.get('child');\n\ncp.spawn('cmd', ['/C', 'start cmd.exe']);","outputs":1,"noerr":0,"x":350,"y":240,"wires":[["40580d5.b2a06f4"]]},{"id":"72ef7328.e481cc","type":"inject","z":"59ec00ab.cbf41","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":140,"wires":[["e84603ae.338ce"]]},{"id":"2ad69a04.951cb6","type":"inject","z":"59ec00ab.cbf41","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":240,"wires":[["d84974f0.390708"]]},{"id":"40580d5.b2a06f4","type":"debug","z":"59ec00ab.cbf41","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":490,"y":240,"wires":[]}]

As long as you mean "local to the computer running Node-RED" - then certainly. I do that all the time.

I think that by using start cmd you are probably throwing the command into a background process from which it isn't returning?

You don't really need start cmd nor even start unless you want to start a detached process. start https://bbc.co.uk for example should start up a browser window and return immediately. (I think, not tested).

You might need to use cmd if you're PC is set to use PowerShell by default instead of cmd.exe or if you need to run a script file that doesn't end in .cmd or .bat.

1 Like

Well, it seems that it sends me the process to a background process

If I start it directly in CMD, each one of the commands that I put works well, but if I use the node-red exec, it starts it in the background

What is it that you are trying to run?

OK, its because I use nssm as a windows service,
if I start node-red from cmd the commands and the exec node works correctly

i was trying to open any aplication from exec node like i do on cmd :sweat_smile:

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