jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.0KB

  1. #! /usr/bin/env python
  2. """
  3. Illustrate how to override a class method to do something
  4. In this case, print the commands being executed as strings
  5. (the commands are usually lists, so this can be misleading)
  6. """
  7. import sys
  8. from waflib import Context, Utils, Logs
  9. def exec_command(self, cmd, **kw):
  10. subprocess = Utils.subprocess
  11. kw['shell'] = isinstance(cmd, str)
  12. txt = cmd
  13. if isinstance(cmd, list):
  14. txt = ' '.join(cmd)
  15. print(txt)
  16. Logs.debug('runner_env: kw=%s' % kw)
  17. try:
  18. if self.logger:
  19. # warning: may deadlock with a lot of output (subprocess limitation)
  20. self.logger.info(cmd)
  21. kw['stdout'] = kw['stderr'] = subprocess.PIPE
  22. p = subprocess.Popen(cmd, **kw)
  23. (out, err) = p.communicate()
  24. if out:
  25. self.logger.debug('out: %s' % out.decode(sys.stdout.encoding or 'iso8859-1'))
  26. if err:
  27. self.logger.error('err: %s' % err.decode(sys.stdout.encoding or 'iso8859-1'))
  28. return p.returncode
  29. else:
  30. p = subprocess.Popen(cmd, **kw)
  31. return p.wait()
  32. except OSError:
  33. return -1
  34. Context.Context.exec_command = exec_command