On Sun, Aug 30, 2009 at 4:43 AM, Tim Chase<python.l...@tim.thechases.com> wrote: >> texts = os.popen('top').readlines() >> print texts >> >> It calls the command line "top" and will print out some texts. >> But first I have to press the keyboard "q" to quit the subprocess "top", >> then the texts will be printed, otherwise it just stands by with blank. >> >> Question >> is. Do you know how to give "q" into my python script so that "top" is >> automatically quit immediately or maybe after 1s and print out the texts. > > Well as a workaround, my version of top (on Debian) supports a "-n" > parameter so you can tell it how many iterations you want it to perform > before quitting. So you should be able to just use > > os.popen('top -n1').readlines()
Hm, interesting. On Mac OS X's (and BSD's?) top, -n instead specifies the number of processes to list at a time (i.e. list only the top N processes), which is entirely different. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list