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: