i have a python script (.py) which i can execute in node-red easily. but i need to pass a json string to my python script as an input. in another word the python script which is on my local drive should read the input from json string in node red and then print the result in message payload. here is my flow
Please see this FAQ entry for how to share your flow. You can edit your previous post to correct it so that it becomes importable.
In the meantime you can append the payload to the command in the exec node so you can pass the string to your script if that is what you mean. If that isn't what you mean then please explain further.
you have add payload unticked - if you tick that then msg.payload will be added to the command line sent to the command as a parameter.
Or if you mean you have a long running python process and need to pass in things to STDIN then you probably need the node-red-node-daemon instead as that provides stdin and stdout to a running process.
(Note for python you may need to add a -u parameter to stop it buffering the output and to send it through immediately)
IMHO if you need this its easier and more flexible to use MQTT to communicate from node-red to your Python code and vice-versa. The Python paho-mqtt library is well documented and the mosquitto MQTT broker is easily run on your localhost (unless its Windows), Node-red makes MQTT easy to use.
Well, I do agree that using MQTT for communication between NR and python (or whatever that is supporting MQTT) is superior to most (tell me, I'm using it all over the places)
But it would require that the python script is already running and able to listen to incoming messages. In this particular case I assume that the author of the topic wished to run a script, pass params to it and then the script would terminate when execution finished
For sure you could create a flow that starts the script, waits for acknowledgement from the script via MQTT that it is ready and then sends the foreseen related parameters with values. But maybe this becomes too complicated if you just want to run a script that terminates when execution is finished
I'm not a big Windows guy, getting off the bus when Windows 8 came out, but my comment was based on helping a friend.
It appeared from my Googling, that mosquitto for Windows required Cygwin to be installed. This was more than he wanted to bite off, and since he had a Raspberry Pi2 sitting idle I suggest using it as the Broker instead.
If there is a windows installer for mosquitto, I'd appreciate the link, as I didn't find it. I like Cygwin, but it can be a challenge for a Windows user with no Linux/Unix experience.
By comparison it was trivial to get Python, OpenCV, nodejs and node-red installed and working on Windows 10. Windows 7 had issues with a missing DLL with the OpenCV (pip install), I was able to solve it with difficulty as there are at least five versions of that DLL kicking around and only one worked for me.