D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
usr
/
lib64
/
python2.7
/
Demo
/
curses
/
Filename :
repeat.py
back
Copy
#! /usr/bin/python2.7 """repeat <shell-command> This simple program repeatedly (at 1-second intervals) executes the shell command given on the command line and displays the output (or as much of it as fits on the screen). It uses curses to paint each new output on top of the old output, so that if nothing changes, the screen doesn't change. This is handy to watch for changes in e.g. a directory or process listing. To end, hit Control-C. """ # Author: Guido van Rossum # Disclaimer: there's a Linux program named 'watch' that does the same # thing. Honestly, I didn't know of its existence when I wrote this! # To do: add features until it has the same functionality as watch(1); # then compare code size and development time. import os import sys import time import curses def main(): if not sys.argv[1:]: print __doc__ sys.exit(0) cmd = " ".join(sys.argv[1:]) p = os.popen(cmd, "r") text = p.read() sts = p.close() if sts: print >>sys.stderr, "Exit code:", sts sys.exit(sts) w = curses.initscr() try: while True: w.erase() try: w.addstr(text) except curses.error: pass w.refresh() time.sleep(1) p = os.popen(cmd, "r") text = p.read() sts = p.close() if sts: print >>sys.stderr, "Exit code:", sts sys.exit(sts) finally: curses.endwin() main()
Name
Size
Last Modified
Owner
Permissions
Actions
README
0.832
KB
April 19 2020 9:13:39
root
0644
life.py
7.177
KB
April 10 2024 4:57:37
root
0755
life.pyc
6.628
KB
April 10 2024 4:58:46
root
0644
life.pyo
6.628
KB
April 10 2024 4:58:46
root
0644
ncurses.py
6.492
KB
April 10 2024 4:57:37
root
0755
ncurses.pyc
5.708
KB
April 10 2024 4:58:46
root
0644
ncurses.pyo
5.708
KB
April 10 2024 4:58:46
root
0644
rain.py
2.347
KB
April 10 2024 4:57:37
root
0755
rain.pyc
2.241
KB
April 10 2024 4:58:46
root
0644
rain.pyo
2.241
KB
April 10 2024 4:58:46
root
0644
repeat.py
1.479
KB
April 10 2024 4:57:37
root
0755
repeat.pyc
1.419
KB
April 10 2024 4:58:46
root
0644
repeat.pyo
1.419
KB
April 10 2024 4:58:46
root
0644
tclock.py
3.253
KB
April 10 2024 4:57:37
root
0755
tclock.pyc
3.563
KB
April 10 2024 4:58:46
root
0644
tclock.pyo
3.563
KB
April 10 2024 4:58:46
root
0644
xmas.py
24.85
KB
April 19 2020 9:13:39
root
0644
xmas.pyc
19.398
KB
April 10 2024 4:58:46
root
0644
xmas.pyo
19.398
KB
April 10 2024 4:58:46
root
0644
2017 © D7net | D704T team