Brigand
Brigand

Reputation: 86240

How can I monitor a screen session with Python?

I need to monitor a screen session in real time using a Python script. It needs to know when the display changes. I believe this can be described as whenever stdout is flushed, or a character is entered to stdin. Is there some way to do this; perhaps with pipes?

I have some code found here that gets a character from stdin, and I assume works on a pipe (if I modify the code, or change sys.stdin)?

Does the flush function of a stream (like stdout) get called in a pipe, or is it just called explicitly? My understanding is that the display is only updated when stdout is flushed.

Upvotes: 0

Views: 2066

Answers (2)

Michael Wild
Michael Wild

Reputation: 26341

Probably you want to take a look at script, which already does pretty much everything you want.

Upvotes: 1

kumar_m_kiran
kumar_m_kiran

Reputation: 4022

Have you tried python curses? It is similar of Linux curses and provides a good way to handle terminal related i/o.

Upvotes: 0

Related Questions