diff --git a/waflib/Context.py b/waflib/Context.py index caa97ec0..214ad2ec 100644 --- a/waflib/Context.py +++ b/waflib/Context.py @@ -308,8 +308,8 @@ class Context(ctx): ret = tsk.generator.bld.exec_command('touch foo.txt') return ret - Do not confuse this method with :py:meth:`waflib.Context.Context.cmd_and_log` which is used to - return the standard output/error values. + This method captures the standard/error outputs (Issue 1101), but it does not return the values + unlike :py:meth:`waflib.Context.Context.cmd_and_log` :param cmd: command argument for subprocess.Popen :param kw: keyword arguments for subprocess.Popen @@ -319,25 +319,31 @@ class Context(ctx): Logs.debug('runner: %r' % cmd) Logs.debug('runner_env: kw=%s' % kw) + if self.logger: + self.logger.info(cmd) + + kw['stdout'] = kw['stderr'] = subprocess.PIPE + try: + p = subprocess.Popen(cmd, **kw) + (out, err) = p.communicate() + except Exception as e: + raise Errors.WafError('Execution failure: %s' % str(e), ex=e) + + if out: + if not isinstance(out, str): + out = out.decode(sys.stdout.encoding or 'iso8859-1') + sys.stdout.write(out) if self.logger: - # warning: may deadlock with a lot of output (subprocess limitation) + self.logger.debug('out: %s' % out) + if err: + if not isinstance(err, str): + err = err.decode(sys.stdout.encoding or 'iso8859-1') + sys.stderr.write(err) + if self.logger: + self.logger.error('err: %s' % err) - self.logger.info(cmd) - - kw['stdout'] = kw['stderr'] = subprocess.PIPE - p = subprocess.Popen(cmd, **kw) - (out, err) = p.communicate() - if out: - self.logger.debug('out: %s' % out.decode(sys.stdout.encoding or 'iso8859-1')) - if err: - self.logger.error('err: %s' % err.decode(sys.stdout.encoding or 'iso8859-1')) - return p.returncode - else: - p = subprocess.Popen(cmd, **kw) - return p.wait() - except OSError: - return -1 + return p.returncode def cmd_and_log(self, cmd, **kw): """ diff --git a/waflib/extras/sync_exec.py b/waflib/extras/sync_exec.py index baf4cfbd..1d5f228e 100644 --- a/waflib/extras/sync_exec.py +++ b/waflib/extras/sync_exec.py @@ -2,30 +2,8 @@ # encoding: utf-8 """ -Force the execution output to be synchronized -May deadlock with a lot of output (subprocess limitation) +This tool is obsolete, the sync_exec feature is now the default """ -import sys -from waflib.Build import BuildContext -from waflib import Utils, Logs - -def exec_command(self, cmd, **kw): - subprocess = Utils.subprocess - kw['shell'] = isinstance(cmd, str) - Logs.debug('runner: %r' % cmd) - Logs.debug('runner_env: kw=%s' % kw) - try: - kw['stdout'] = kw['stderr'] = subprocess.PIPE - p = subprocess.Popen(cmd, **kw) - (out, err) = p.communicate() - if out: - sys.stdout.write(out.decode(sys.stdout.encoding or 'iso8859-1')) - if err: - sys.stdout.write(err.decode(sys.stdout.encoding or 'iso8859-1')) - return p.returncode - except OSError: - return -1 - -BuildContext.exec_command = exec_command +pass