Browse Source

Read from stdout in real-time

Matthias Vogelgesang 7 years ago
parent
commit
b2590f6cc7
1 changed files with 7 additions and 8 deletions
  1. 7 8
      cockpit

+ 7 - 8
cockpit

@@ -116,7 +116,7 @@ class LogList(LineList):
 
 
 class CommandList(LineList):
-    
+
     def __init__(self, window, colors):
         self.line_list = LineList(window)
         self.normal = colors.get(Colors.NORMAL)
@@ -197,15 +197,14 @@ class Application(object):
         try:
             p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
-            stdout, stderr = p.communicate()
+            for line in iter(p.stdout.readline, ''):
+                self.log.info(line)
 
-            def output_lines(pipe, log_func):
-                for line in pipe.split(os.linesep):
-                    if line:
-                        log_func(line)
+            for line in iter(p.stderr.readline, ''):
+                self.log.error(line)
 
-            output_lines(stdout, self.log.info)
-            output_lines(stderr, self.log.error)
+            while p.poll() is None:
+                pass
 
             if p.returncode == 0:
                 self.log.success("done")