Background output of script

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
YellowSky
Posts: 65
Joined: Tuesday 12 May 2015 12:09
Target OS: Raspberry Pi / ODroid
Domoticz version: Last
Location: Belgium
Contact:

Background output of script

Post 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
gerardvs
Posts: 81
Joined: Sunday 04 January 2015 0:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest-1
Location: /dev/null
Contact:

Re: Background output of script

Post 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
YellowSky
Posts: 65
Joined: Tuesday 12 May 2015 12:09
Target OS: Raspberry Pi / ODroid
Domoticz version: Last
Location: Belgium
Contact:

Re: Background output of script

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest