'result 1' for event commands, where does output go?

Have a MythTV related problem? Ask for help from other MythTV users here.

Moderator: Forum Moderators

Post Reply
wmorrison
Senior
Posts: 165
Joined: Sat Dec 01, 2018 12:05 am
United States of America

'result 1' for event commands, where does output go?

Post by wmorrison »

I have a few scripts that run on events. Usually, when I first start testing them (actually run by MythTV) I only see 'result 1' (failure) in mythbackend.log but any output from the script is lost. Any tips on debugging? Does the output get logged anywhere?

I have other scripts that are running, so I already know to check ownership and mode of files accessed/written. I even have them writing both stdout and stderr to a specific log file. The script works when I run it in xterm, even when I copy the full command out of mythbackend.log. I've compared the values for working jobs to the non-working one in table settings for values EventCmd* and see no mistakes there.

Every time I make a new event or job script I go through this. No output about what's going wrong, even though my script should write it to a log file (and does, for the working event scripts.)
User avatar
bill6502
Developer
Posts: 2323
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: 'result 1' for event commands, where does output go?

Post by bill6502 »

Any output from a script is lost unless the user sends it to a file as you've
mentioned above.

If you haven't, run with -v system:debug and you may get some more
clues, buy only about the command being run and results. Not script
output. mythbackend --setverbose system:debug lets you change it
on a running backend. system:alert turns it off.

If you use the Python bindings, there is a logging module that provides
the 'traditional' mythAnyProgramName switches. You can do:

Code: Select all

from MythTV import MythLog
...
MythLog.loadArgParse(parser)
logger = MythLog(module='your command name')
...
# And, just a sample:
logger(MythLog.GENERAL, MythLog.INFO, "***** Job arguments.", job.args)
and then pass command like arguments like. Just type yourPython.py --help
to see what's available. Of course you can add any additional switches you
like. I use the argparse module for that.
wmorrison
Senior
Posts: 165
Joined: Sat Dec 01, 2018 12:05 am
United States of America

Re: 'result 1' for event commands, where does output go?

Post by wmorrison »

Ugh! Figured it out.

I was putting all my imports at the top of my Python script, where they're "supposed" to be.

Then defining a logger class and redirecting stdout and stderr to it.

Problem is, there was a ModuleNotFoundError happening before the logger got set up.

I moved all imports except sys below the logger setup, and now I see the ModuleNotFoundError in my log file.

[smacks forehead]
wmorrison
Senior
Posts: 165
Joined: Sat Dec 01, 2018 12:05 am
United States of America

Re: 'result 1' for event commands, where does output go?

Post by wmorrison »

wmorrison wrote:
Sat May 22, 2021 8:56 pm
Problem is, there was a ModuleNotFoundError happening before the logger got set up.
That is, my user finds the module, but user mythtv doesn't.
User avatar
bill6502
Developer
Posts: 2323
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: 'result 1' for event commands, where does output go?

Post by bill6502 »

My full 'top-o-script':

Code: Select all

#!/usr/bin/python3                                                             
# -*- coding: UTF-8 -*-                                                        
                                                                               
''' Test MythTV job features '''                                               
                                                                               
import argparse                                                                
import os                                                                      
import sys                                                                     
from MythTV import (exceptions, Job, MythDB, MythLog)
I use argparse before MythLog. The default v31+ is build is with python3.

I agree that most of the time, imports belong at the top. pylint is happy with mine.
Post Reply