summaryrefslogtreecommitdiff
path: root/morphlib/execute.py
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2011-11-04 15:04:55 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2011-11-04 15:04:55 +0000
commit73e7fb54aa5528c1fd571c4dfe9662a4eca314b4 (patch)
tree7518e3b95497e49be9aca5e59e2356c6e3818a4c /morphlib/execute.py
parentccf842c47a22248c77b7065898ab840ac76bed64 (diff)
downloadmorph-73e7fb54aa5528c1fd571c4dfe9662a4eca314b4.tar.gz
Combine stdout and stderr when running programs
Too many build tools and compilers produce a confusing mix of stdout and stderr output, which need to be read interleaved for things to make sense.
Diffstat (limited to 'morphlib/execute.py')
-rw-r--r--morphlib/execute.py29
1 files changed, 10 insertions, 19 deletions
diff --git a/morphlib/execute.py b/morphlib/execute.py
index 02e7e196..49764bff 100644
--- a/morphlib/execute.py
+++ b/morphlib/execute.py
@@ -23,17 +23,8 @@ import morphlib
class CommandFailure(Exception):
- def __init__(self, command, stdout, stderr, exit):
- Exception.__init__(self,
- 'Command failed: %s\n'
- 'Standard output:\n%s\n'
- 'Standard error:\n%s\n'
- 'Exit code: %s' %
- (command,
- morphlib.util.indent(stdout),
- morphlib.util.indent(stderr),
- exit))
-
+ def __init__(self, command):
+ Exception.__init__(self, 'Command failed: %s' % command)
class Execute(object):
@@ -66,15 +57,15 @@ class Execute(object):
argv = ['fakeroot'] + argv
p = subprocess.Popen(argv, shell=False,
stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
env=self.env,
cwd=self.dirname)
out, err = p.communicate()
logging.debug('Exit code: %d' % p.returncode)
- logging.debug('Standard output:\n%s' % morphlib.util.indent(out))
- logging.debug('Standard error:\n%s' % morphlib.util.indent(err))
+ logging.debug('Standard output and error:\n%s' %
+ morphlib.util.indent(out))
if p.returncode != 0:
- raise CommandFailure(command, out, err, p.returncode)
+ raise CommandFailure(command)
stdouts.append(out)
return stdouts
@@ -92,13 +83,13 @@ class Execute(object):
argv = ['fakeroot'] + argv
self.msg('# %s' % ' '.join(argv))
p = subprocess.Popen(argv, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, cwd=self.dirname)
+ stderr=subprocess.STDOUT, cwd=self.dirname)
out, err = p.communicate()
logging.debug('Exit code: %d' % p.returncode)
- logging.debug('Standard output:\n%s' % morphlib.util.indent(out))
- logging.debug('Standard error:\n%s' % morphlib.util.indent(err))
+ logging.debug('Standard output and error:\n%s' %
+ morphlib.util.indent(out))
if p.returncode != 0:
- raise CommandFailure(' '.join(argv), out, err, p.returncode)
+ raise CommandFailure(' '.join(argv))
return out