Page 1 of 1

Background output of script

Posted: Thursday 23 March 2017 6:33
by YellowSky
Hi everyone,
i would like to launch a command line in the On/Off action of a switch.
Is it possible?

Currently, i use

Code: Select all

script:///home/pi/domoticz/scripts/python/script.py & (with or without "&")
but i would like to be able to see the output of the script in case of.
Therefore i think about launch the script in a "screen"

but when i try

Code: Select all

script:///screen -dmS water /home/pi/domoticz/scripts/python/script.py
it does not work.

Have you got an idea to run a command directly in the "action"? Or another way to be able to see the output of a script is executing under raspbian?

Thank you

Re: Background output of script

Posted: Friday 24 March 2017 8:25
by gerardvs
You have several options to do this.
Screen I would not advise to use because you should either run Domoticz within a screen session or start a separate subproces of screen an launch you commands. This is in my opinion a bit clumsy and using a subproces you effectively detach from Domoticz. There is a bit of a neat way to start a subproces but only follow that path if there is no other way like having 3rd party software and you want to redirect stdout and stderr.

We don't know the content of your script but I would either log to Domoticz or log to a file on the filesystem (e.g. /tmp/script.log). From another session you could tail the logfile (tail -f /tmp/script.log). Of course you should keep the logfile within a reasonable size which can be don from within or outside the script.

Hope this helps a bit but showing the code and telling what you want will help in finding a solution.

--Gerard

Re: Background output of script

Posted: Saturday 25 March 2017 15:20
by YellowSky
Thank you for your answer.
To be honest i'm looking for a generic solution without file.

I would like to see a print variable of a python script.
But in general i would like see the output of a background script.