문제

My application is invoked from run.py. I've installed Pygments and I'd like to redirect Python's output so that as tracebacks occur, they're formatted in an easier to read format.

This is the command that I've tried, python run.py 2>&1 | pygmentize -l py

Redirecting both stdout and stderr through pygmentize. The pygmentize documentation says that it will read from stdin if no file is provided, "If no input file is given, use stdin, if -o is not given, use stdout."

However, when I redirect like this, no output--errors or log statements or anything else--is output to my terminal.

When I run my command without piping its output into pygmentize, i.e. python run.py 2>&1 I get this output:

INFO:werkzeug: * Running on http://0.0.0.0:5000/
INFO:werkzeug: * Restarting with reloader

Any suggestions?

도움이 되었습니까?

해결책

pygmentize reads the whole input stream when reading from stdin and only outputs everything if the input stream is closed, so you only will get any output piped through pygments after your first process has ended.

I'm afraid there's little you can do about that. If you want to format a continuous stream, You could only try to write your own wrapper around pygments wich reads the input stream in chunks and feeds that to pygments.

The reason why you don't see any output at all now is that you're probably using Ctrl+C to stop your process in the shell, but that kills both processes. If you use kill to only terminate the server process, then you should see at least the lines you mentioned above going through pygments.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top