2

I have a python script that will write some general logging to the console. I've redirected this to a log file using the typical python -u jbot.py | tee -a jbot.log. This works fine, I get console output and logfile input. However, when attempting to run this under screen:

screen python -u jbot.py | tee -a jbot.log

I don't get any of the logging output to my file. Once I've disconnected from screen, does console output for that session get suppressed entirely, or is there a way I can still have logfile input from the stdout and stderr of my script?

I realize using a logging library would probably solve this (since I'm screening anyhow), but for now I want to stick with capturing console output (if possible) until I can properly integrate a logging module into my code.

  • That's a convoluted theory, but is there a chance that your script tries to assess the terminal's capabilities before writing to it, and decides that "screen" is not suitable? (The fact that you are piping to tee should make the writing process consider its output "not a terminal", which is why I call the theory convoluted.) – dhag Feb 3 '17 at 16:36
4

You need to do something like this:

screen sh -c 'python -u jbot.py | tee -a jbot.log'

Basically, before you were piping the output of screen (not of your python script directly) to the log. Screen takes a command to execute as its argument, which it does itself not using a shell. So you need to explicitly make it run a shell.

Another option is to use screen's built-in output logging; see the -L option (also available inside screen via its UI).

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.