blob: b0fe1f17c5ae5667c3433643d52098d5383b44d1 (
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
29
30
31
32
33
34
35
|
#!/usr/bin/env python2.5
"""context-rlwrap -- a simple readline wrapper
Usage: context-rlwrap [some other program and args]
Wraps the plain stdin-based input mechanism of the given program into a
convenient readline-based one.
"""
import os
import sys
import signal
import readline
if len(sys.argv) < 2:
sys.exit(__doc__)
rfd, wfd = os.pipe()
pid = os.fork()
if pid == 0:
os.close(wfd)
os.dup2(rfd, 0)
sys.argv.pop(0)
os.execvp(sys.argv[0], sys.argv)
else:
def childied(n, f):
p, ec = os.waitpid(pid, 0)
sys.exit(ec)
signal.signal(signal.SIGCHLD, childied)
os.close(rfd)
try:
while True:
l = raw_input()
os.write(wfd, l + '\n')
except (KeyboardInterrupt, SystemExit): raise
except: pass
|