Can anybody explain how Output is recovered when call Exec?

Hi Guys

I'm using Exec to call a python script, but for some reason, when I output using print(), its not being returned to Node-RED. Yet, it receives the debug output from using the logging library - I've also tried sending output to sys.stdout.write() and sys.stderr.write() and neither of then are returned.

I'm going to do a bit more digging - But I was wondering if anybody could offer some insight or suggestions?

Hi, I know it's a big read - the last line of the exec node info panel on the right is...

" Tip: if running a Python app you may need to use the -u parameter to stop the output being buffered. "

1 Like

Thanks dceejay, I was praying that would work, but its still not working.

My tests script is simple:

#!/usr/bin/python3 -u
import os
print("Test Out....")

I've tried calling the script directly, and also with the python interpreter.

python -u /vm-scripts/test.py

I did also try using the pythonshell node, which did work for returning the output, but I ran into a different issue, in I cannot easily pass parameters to the script with this.

Should work fine.. here is my test flow

[{"id":"bcb67ebc.b1eca","type":"inject","z":"ff27ff95.cc8d5","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":149,"y":847,"wires":[["24eae0e2.b038"]]},{"id":"24eae0e2.b038","type":"exec","z":"ff27ff95.cc8d5","command":"python","addpay":false,"append":"-u /tmp/test.py","useSpawn":"false","timer":"","oldrc":false,"name":"","x":299,"y":847,"wires":[["8647d03c.afbcb"],[],[]]},{"id":"8647d03c.afbcb","type":"debug","z":"ff27ff95.cc8d5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":469,"y":847,"wires":[]}]
1 Like

@dceejay you sir, are a superstar, thank you so much. I was pulling my hair out with this for the past several evenings.. My mistake it seems, I was putting the full path script in the "Command" field.

Its not working

Command failed: python3 1611499717485 -u dht_simpletest.pypython3: can't open file '1611499717485': [Errno 2] No such file or directory

do we need to use different command when node=red is installed on docker , I am using IOTstack on docker

Did you leave the append msg.payload option checked? Because this looks like you by accident appended a timestamp (probably from the inject node) to your commands.
But please open a new thread for questions like this as its no good appending your question to a two year old thread.

Have you figured out why it was not running

Look at the command it was trying to run, it is in the error message. Is that the command you want to run?