4
Illustrate how to override a class method to do something
6
In this case, print the commands being executed as strings
7
(the commands are usually lists, so this can be misleading)
11
from waflib import Context, Utils, Logs
13
def exec_command(self, cmd, **kw):
14
subprocess = Utils.subprocess
15
kw['shell'] = isinstance(cmd, str)
18
if isinstance(cmd, list):
22
Logs.debug('runner_env: kw=%s' % kw)
26
# warning: may deadlock with a lot of output (subprocess limitation)
30
kw['stdout'] = kw['stderr'] = subprocess.PIPE
31
p = subprocess.Popen(cmd, **kw)
32
(out, err) = p.communicate()
34
self.logger.debug('out: %s' % out.decode(sys.stdout.encoding or 'iso8859-1'))
36
self.logger.error('err: %s' % err.decode(sys.stdout.encoding or 'iso8859-1'))
39
p = subprocess.Popen(cmd, **kw)
44
Context.Context.exec_command = exec_command