Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python2
- import os
- import sys
- import fcntl
- import subprocess
- import select
- f = open('/tmp/sendmail.args', 'a')
- f.write('-->>> ' + ' '.join(sys.argv) + '\n')
- f.flush()
- p = subprocess.Popen(['/usr/sbin/sendmail.backup'] + sys.argv[1:], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- def setNonBlocking(fd):
- flags = fcntl.fcntl(fd, fcntl.F_GETFL)
- flags = flags | os.O_NONBLOCK
- fcntl.fcntl(fd, fcntl.F_SETFL, flags)
- setNonBlocking(sys.stdin.fileno())
- setNonBlocking(p.stdout.fileno())
- setNonBlocking(p.stderr.fileno())
- while True:
- rr, _, _ = select.select([sys.stdin, p.stdout, p.stderr], [], [])
- for r in rr:
- data = r.read()
- if not data:
- exit(0)
- if r == sys.stdin:
- f.write('>>> ' + data)
- f.flush()
- p.stdin.write(data)
- if r == p.stdout:
- f.write('<<< ' + data)
- f.flush()
- sys.stdout.write(data)
- sys.stdout.flush()
- if r == p.stderr:
- sys.stderr.write(data)
- sys.stderr.flush()
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment