473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Example of using pty to control a process?

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
2 3912
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Srijit Kumar Bhadra | last post by:
Hello, Here is some sample code with pywin32 build 203 and ctypes 0.9.6. Best regards, /Srijit File: SharedMemCreate_Mutex_win32all.py # This application should be used with...
0
by: grutta | last post by:
I am writing a windows service that will recieve notification when a USB Device is insterted into the machine. I have used the RegisterDeviceNotification and the RegisterServiceCtrlHandlerEx with...
7
by: pfa | last post by:
I have a udf which returns a table. I was hoping to access the NEXTVAL from a sequence to affect the logic flow and consequently the return result. I'm using a LANGUAGE C type function. Here's...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
5
by: Miyra | last post by:
Hi. I'm working with an app that uses exceptions for control flow. These are code blocks where exceptions are thrown/caught regularly. A couple hundred exceptions occur per hour and they're caught...
13
by: Brian Henry | last post by:
I just wrote this in about 5 minutes, can someone have a look at it and leme know it this is a good way to do things like this? each item on the control is a object which has its own render...
0
by: Pavan | last post by:
My name is Pavan and I am a software engineer working on ASP .Net web development. Currently I am using .Net 2.0 Professional Edition to develop my web pages. I have a problem
7
by: =?Utf-8?B?U2ltb24gVGFtbWFu?= | last post by:
I was trying to double buffer a control while drawing on CE devices. The code below is compiled under the compact framework but you can also run it on the desktop and it produces the same problem....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.