Running multiple processes and capturing output in python with pygtk
I would like to write a simple application that launches several programs and displays their output in several terminal (style) windows. Also, I want to be able to read the stdout / stderr of these processes and look for keywords in the output.
I tried to implement these two ways in python, the first is using subprocess.Popen and the second is vte (python-vte).
I just got Popen to work with the survey. I have to constantly check if processes have data to read, read data, and then send it to my TextArea. It has been recommended to use gobject.io_add_watch () instead, but whenever I try to get my program to hang in the second call to io_add_watch - it seems to only be able to process one file descriptor at a time.
vte works great, but I haven't found a reliable way to capture the output. You can get a callback when the cursor is moved and then escaped with scrape w / get_text (), but I'm already running into situations where these programs I'm looking at generate an obscene relationship to the tty in one go and then to the screen. There seems to be no callback that contains the new text to add to the window.
Any ideas?
I did something similar to this using subprocess.Popen . For each process, I actually redirected stdout and stderr to a temporary file, then periodically check the file for updates, and dump the output to the TextView .
The reason for not using a pipe for a process was that the processes themselves were unstable and prone to segfaults. When this happened, I sometimes lost data between the last read and the segfault (this was the most needed data to determine the cause of the segfault).
As it turns out, sometimes I would like to save the result from a specific process, so this method worked well for me.
a source to share
If you go with igkuk's suggestion I got some good advice on looking at the files for changes in the related question. This worked pretty well for me (I was looking at the log file for changes).
a source to share