Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Example of using pty to control a process?

Reply
Thread Tools

Example of using pty to control a process?

 
 
morphex
Guest
Posts: n/a
 
      01-06-2005
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

 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a
 
      01-06-2005
On 2005-01-06, morphex <(E-Mail Removed)> 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...
 
Reply With Quote
 
 
 
 
morphex
Guest
Posts: n/a
 
      01-06-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: The pty module, reading from a pty, and Python 2/3 David Hutto Python 0 10-24-2012 06:33 AM
Re: The pty module, reading from a pty, and Python 2/3 David Hutto Python 0 10-24-2012 06:02 AM
Re: The pty module, reading from a pty, and Python 2/3 Evan Driscoll Python 0 10-24-2012 03:41 AM
Re: The pty module, reading from a pty, and Python 2/3 Evan Driscoll Python 0 10-24-2012 03:03 AM
The pty module, reading from a pty, and Python 2/3 Evan Driscoll Python 0 10-24-2012 02:59 AM



Advertisments