Skip to content

Commit

Permalink
Fix mmpipe example to use common tools
Browse files Browse the repository at this point in the history
  • Loading branch information
dagwieers committed Nov 30, 2013
1 parent 5f5481b commit 229d609
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions examples/mmpipe.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 229d609

Please sign in to comment.