2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-22 18:07:12 +01:00

Issue 1101

This commit is contained in:
Thomas Nagy 2012-02-06 02:07:18 +01:00
parent 959e450043
commit 2263d60b8d
2 changed files with 26 additions and 42 deletions

View File

@ -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):
"""

View File

@ -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