Handle remctl results that are larger than a single pipe buffer
[invirt/packages/invirt-base.git] / python / invirt / remctl.py
index 465d31c..956ca2d 100644 (file)
@@ -4,6 +4,7 @@ Functions to perform remctls.
 
 from invirt.common import CodeError
 import subprocess
+import sys
 from socket import getfqdn
 
 def kinit(principal=None, keytab=None):
@@ -34,11 +35,11 @@ def remctl(host, *args, **kws):
                          + list(args),
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
-    v = p.wait()
+    stdout, stderr = p.communicate()
     if kws.get('err'):
-        return p.stdout.read(), p.stderr.read()
-    if v:
-        print >> sys.stderr, 'Error', v, 'on remctl', args, ':'
-        print >> sys.stderr, p.stderr.read()
+        return stdout, stderr
+    if p.returncode:
+        print >> sys.stderr, 'Error', p.returncode, 'on remctl', args, ':'
+        print >> sys.stderr, stderr
         raise CodeError('ERROR on remctl')
-    return p.stdout.read()
+    return stdout