Commits

Anonymous committed 8570541

Issue 1101

  • Participants
  • Parent commits 270cad8

Comments (0)

Files changed (2)

waflib/Context.py

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

waflib/extras/sync_exec.py

 # 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
+pass
 
-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
-