summaryrefslogtreecommitdiff
path: root/pexpect/examples/step.py
blob: f11766749246f977af4451e7c0e5a53cd163415c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python

# This single steps through a log file.

import tty, termios, sys

def getkey():
	file = sys.stdin.fileno()
	mode = termios.tcgetattr(file)
	try:
		tty.setraw(file, termios.TCSANOW)
		ch = sys.stdin.read(1)
	finally:
		termios.tcsetattr(file, termios.TCSANOW, mode)
	return ch

fin = open ('log', 'rb')
fout = open ('log2', 'wb')

while 1:
	foo = fin.read(1)
	if foo == '':
		sys.exit(0)
	sys.stdout.write(foo)
	getkey()
	fout.write (foo)
	fout.flush()