0

I have a code like this

#...
os.system('clear')
while true:
     result=os.popen('myscript.sh')
     print(result.read())

I want to show this result on top every time I print it out. Like what a "watch" command do.

So, How to?

Bing
  • 52
  • 1
  • 8
  • Do you want a [curses solution that moves the cursor](http://stackoverflow.com/questions/4897359/output-to-the-same-line-overwriting-previous-output-python-2-5/8436827#8436827) or just a [simple overwrite of the first line](http://stackoverflow.com/questions/4897359/output-to-the-same-line-overwriting-previous-output-python-2-5/8436827#8436827)? – LinkBerest Feb 11 '16 at 03:36
  • Maybe the latter one. the sh script needs to take seconds to be finished so I can't just use a clear she'll command to do so. BTW, Is curses solution a terminal output standard? – Bing Feb 11 '16 at 03:43
  • 1
    standard? not sure but it is [certainly a common one](http://linux.die.net/man/3/ncurses). Again though, you need to expand your question to better describe what you want to do to determine if one needs a `\r` option or a [stdscr.addstr(0,0,"Top o'the page, ma!")](https://docs.python.org/3.5/howto/curses.html#curses-howto) – LinkBerest Feb 11 '16 at 03:54
  • Sorry, I don't know how to describe what I am doing. I just want the print() prints result on the top screen of terminal – Bing Feb 11 '16 at 04:05

0 Answers0