Example of using pty to control a process?

Grant Edwards grante at visi.com
Thu Jan 6 03:20:00 CET 2005

On 2005-01-06, morphex <morphex at gmail.com> wrote:

> I'm trying to get the output from the command top on Linux, using
> python.  I'd like to start top, get a page of output, and then send top
> the letter 'q' to end the process.

Man, you like to do things the hard way.  Me OTOH, I'm lazy.
I'd use popen(), start top in "batch" mode and tell it to
execute one iteration.

 import os
 lines = os.popen("top -b -n 1","r").read().split('\n')
 print lines

> Looking around I've figured that the module pty can be used
> for this, however, I can't find any good examples of how to
> use it. Any ideas as to where I can look?

I've you're dead set on using pty, I can tell you how to do it
in C, and maybe you can extrapolate.

Grant Edwards                   grante             Yow!  .. I think I'd
                                  at               better go back to my DESK
                               visi.com            and toy with a few common

More information about the Python-list mailing list