Skip to content
Browse files

Fix mmpipe example to use common tools

  • Loading branch information...
1 parent 5f5481b commit 229d609a027c6b74fe4677c74b27907768c151eb @dagwieers committed Nov 30, 2013
Showing with 14 additions and 5 deletions.
  1. +14 −5 examples/mmpipe.py
View
19 examples/mmpipe.py 100644 → 100755
@@ -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

0 comments on commit 229d609

Please sign in to comment.
Something went wrong with that request. Please try again.