File: sync_exec.py

package info (click to toggle)
xmds2 3.0.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 52,068 kB
  • sloc: python: 63,652; javascript: 9,230; cpp: 3,929; ansic: 1,463; makefile: 121; sh: 54
file content (31 lines) | stat: -rw-r--r-- 778 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#! /usr/bin/env python3
# encoding: utf-8

"""
Force the execution output to be synchronized
May deadlock with a lot of output (subprocess limitation)
"""

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