By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,236 Members | 1,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,236 IT Pros & Developers. It's quick & easy.

Example of using pty to control a process?

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 2005-01-06, morphex <mo*****@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
MISAPPREHENSIONS...
Jul 18 '05 #2

P: n/a
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

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.