Example of using pty to control a process?

M

morphex

Hi,

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.

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?

Thanks,

Morten
 
G

Grant Edwards

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.
 
M

morphex

Oh right. I knew about the -b option, but not the -n 1 option (which
isn't required on FreeBSD). Thanks, I'll obviously use that instead!
:)

Regards,

Morten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top