Need help using stderr and stdout in python3 script

Posted on
Fri Dec 23, 2022 12:31 pm
hwitten offline
Posts: 627
Joined: Dec 26, 2007
Location: British Columbia

Need help using stderr and stdout in python3 script

I'm troubleshooting a script that gets data into Indigo from Home Assistant, bypassing MQTT.
It would help me to send some text to stdout and hopefully get some info via stderr but haven't figured out how to do that. My script works from the command line but running embedded or via external is not cooperating.
Being new to Python doesn't make it easy :)
I've been sending my troubleshooting text to the events log but am hoping that using stdout and stderr might allow some extra flexibility. A sampling or pointer to a post would be much appreciated. I searched, but...

Posted on
Tue Dec 27, 2022 12:06 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Need help using stderr and stdout in python3 script

stdout and stderr are both captured by the process that runs Indigo scripts and it not passed any further. Generally, writing it to the Indigo Event Log is the right way to go.

If you want your own log file, you can read up on the Python logging functionality (which is super flexible) and use your own logger and handler to write to your own files. Plugins have their own loggers automatically, but for a script you'd want to create your own.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Dec 27, 2022 8:27 pm
hwitten offline
Posts: 627
Joined: Dec 26, 2007
Location: British Columbia

Re: Need help using stderr and stdout in python3 script

Is writing line by line to the event log the only option for debugging embedded python scripts?

Or am I missing something? Seems there has to be a better way :)

Posted on
Wed Dec 28, 2022 6:46 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Need help using stderr and stdout in python3 script

If you don't want the debugging output to go to the events log, then you have to create your own logger instance as Jay said. There's some helpful information on this Indigo Wiki page. You can use this method to send the output to another logging file.

Another option is to run the script from the Indigo Scripting Shell. You'll need to do this from the local client machine. You can do this with the following command in Terminal:

Code: Select all
indigo-host -x '/SomeFolder/indigo_script.py'
The indigo-host helper application is located in:

Code: Select all
usr/local/bin/
along with a few others:
Code: Select all
indigo-clean-and-zip-plugin   
indigo-host         
indigo-restart-plugin
indigo-start
indigo-stop

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests