Ubuntu Pastebin

Paste from Andrew Jorgensen at Wed, 14 Jun 2017 17:22:34 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 415ca37..9639396 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1805,10 +1807,9 @@ def subp(args, data=None, rcs=None, env=None, capture=True, shell=False,
                        "input/output logstring: %s"), logstring)
 
         stdin = None
-        stdout = None
         stderr = None
+        stdout = subprocess.PIPE
         if capture:
-            stdout = subprocess.PIPE
             stderr = subprocess.PIPE
         if data is None:
             # using devnull assures any reads get null, rather
@@ -1823,7 +1824,23 @@ def subp(args, data=None, rcs=None, env=None, capture=True, shell=False,
         sp = subprocess.Popen(args, stdout=stdout,
                               stderr=stderr, stdin=stdin,
                               env=env, shell=shell)
-        (out, err) = sp.communicate(data)
+
+        if capture:
+            (out, err) = sp.communicate(data)
+        else:
+            # Some processes are less chatty when disconnected from a tty.
+            (out, err) = None, None
+            if data is not None:
+                try:
+                    sp.stdin.write(data)
+                # Borrowed from cpython 2.7 subprocess.py
+                except IOError as e:
+                    if e.errno != errno.EPIPE and e.errno != errno.EINVAL:
+                        raise
+                sp.stdin.close()
+            while sp.poll() is None:
+                sys.stdout.write(sp.stdout.readline())
+                sys.stdout.flush()
 
         # Just ensure blank instead of none.
         if not out and capture:
Download as text