From 229d609a027c6b74fe4677c74b27907768c151eb Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Sat, 30 Nov 2013 01:09:40 +0100 Subject: [PATCH] Fix mmpipe example to use common tools --- examples/mmpipe.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) mode change 100644 => 100755 examples/mmpipe.py diff --git a/examples/mmpipe.py b/examples/mmpipe.py old mode 100644 new mode 100755 index ec173e4..5c93567 --- a/examples/mmpipe.py +++ b/examples/mmpipe.py @@ -8,14 +8,20 @@ def readpipe(file, tmout = 0.001): pass while select.select([file.fileno()], [], [], tmout)[0]: ret = ret + file.read(1) - return ret.split('\n') + return ret.split('\n') def dpopen(cmd): "Open a pipe for reuse, if already opened, return pipes" global pipes if 'pipes' not in globals().keys(): pipes = {} if cmd not in pipes.keys(): - pipes[cmd] = os.popen3(cmd, 't', 0) + try: + import subprocess + p = subprocess.Popen(cmd, shell=False, bufsize=0, close_fds=True, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + pipes[cmd] = (p.stdin, p.stdout, p.stderr) + except ImportError: + pipes[cmd] = os.popen3(cmd, 't', 0) return pipes[cmd] ### Unbuffered sys.stdout @@ -24,12 +30,15 @@ def dpopen(cmd): ### Main entrance if __name__ == '__main__': try: - stdin, stdout, stderr = dpopen('/usr/lpp/mmfs/bin/mmpmon -p -s') - stdin.write('reset\n') +# stdin, stdout, stderr = dpopen('/usr/lpp/mmfs/bin/mmpmon -p -s') +# stdin.write('reset\n') + stdin, stdout, stderr = dpopen('/bin/bash') + stdin.write('uname -a\n') readpipe(stdout) while True: - stdin.write('io_s\n') +# stdin.write('io_s\n') + stdin.write('cat /proc/stat\n') for line in readpipe(stdout): print line