Example of using pty to control a process?

Discussion in 'Python' started by morphex, Jan 6, 2005.

  1. morphex

    morphex Guest

    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
     
    morphex, Jan 6, 2005
    #1
    1. Advertising

  2. On 2005-01-06, morphex <> 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...
     
    Grant Edwards, Jan 6, 2005
    #2
    1. Advertising

  3. morphex

    morphex Guest

    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
     
    morphex, Jan 6, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Evan Driscoll
    Replies:
    0
    Views:
    230
    Evan Driscoll
    Oct 24, 2012
  2. Evan Driscoll
    Replies:
    0
    Views:
    183
    Evan Driscoll
    Oct 24, 2012
  3. Evan Driscoll
    Replies:
    0
    Views:
    209
    Evan Driscoll
    Oct 24, 2012
  4. David Hutto
    Replies:
    0
    Views:
    221
    David Hutto
    Oct 24, 2012
  5. David Hutto
    Replies:
    0
    Views:
    204
    David Hutto
    Oct 24, 2012
Loading...

Share This Page