diff --git a/cloudinit/util.py b/cloudinit/util.py
index 415ca37..672d3e4 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1,10 +1,12 @@
# Copyright (C) 2012 Canonical Ltd.
# Copyright (C) 2012, 2013 Hewlett-Packard Development Company, L.P.
# Copyright (C) 2012 Yahoo! Inc.
+# Copyright (C) 2017 Amazon.com, Inc. or its affiliates.
#
# Author: Scott Moser <scott.moser@canonical.com>
# Author: Juerg Haefliger <juerg.haefliger@hp.com>
# Author: Joshua Harlow <harlowja@yahoo-inc.com>
+# Author: Andrew Jorgensen <ajorgens@amazon.com>
#
# This file is part of cloud-init. See LICENSE file for license information.
@@ -1776,7 +1778,6 @@ def delete_dir_contents(dirname):
def subp(args, data=None, rcs=None, env=None, capture=True, shell=False,
logstring=False, decode="replace", target=None, update_env=None):
-
# not supported in cloud-init (yet), for now kept in the call signature
# to ease maintaining code shared between cloud-init and curtin
if target is not None:
@@ -1805,10 +1806,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 +1823,15 @@ 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
+ while sp.poll() is None:
+ sys.stdout.write(p.stdout.readline())
+ sys.stdout.flush()
# Just ensure blank instead of none.
if not out and capture: