Example of using pty to control a process?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • morphex

    #1

    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

  • Grant Edwards

    #2
    Re: Example of using pty to control a process?

    On 2005-01-06, morphex <morphex@gmail. com> wrote:
    [color=blue]
    > 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.[/color]

    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
    [color=blue]
    > 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?[/color]

    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
    MISAPPREHENSION S...

    Comment

    • morphex

      #3
      Re: Example of using pty to control a process?

      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

      Comment

      Working...