当前位置: 首页>>代码示例>>Python>>正文


Python Utils.check_exe方法代码示例

本文整理汇总了Python中waflib.Utils.check_exe方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.check_exe方法的具体用法?Python Utils.check_exe怎么用?Python Utils.check_exe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在waflib.Utils的用法示例。


在下文中一共展示了Utils.check_exe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
	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)
		if self.logger:
			self.logger.info(cmd)
		if'stdout'not in kw:
			kw['stdout']=subprocess.PIPE
		if'stderr'not in kw:
			kw['stderr']=subprocess.PIPE
		if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]):
			raise Errors.WafError("Program %s not found!"%cmd[0])
		wargs={}
		if'timeout'in kw:
			if kw['timeout']is not None:
				wargs['timeout']=kw['timeout']
			del kw['timeout']
		if'input'in kw:
			if kw['input']:
				wargs['input']=kw['input']
				kw['stdin']=Utils.subprocess.PIPE
			del kw['input']
		try:
			if kw['stdout']or kw['stderr']:
				p=subprocess.Popen(cmd,**kw)
				(out,err)=p.communicate(**wargs)
				ret=p.returncode
			else:
				out,err=(None,None)
				ret=subprocess.Popen(cmd,**kw).wait(**wargs)
		except Exception ,e:
			raise Errors.WafError('Execution failure: %s'%str(e),ex=e)
开发者ID:hakiri,项目名称:sdn-ns-3,代码行数:35,代码来源:Context.py

示例2: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
	def exec_command(self,cmd,**kw):
		subprocess=Utils.subprocess
		kw['shell']=isinstance(cmd,str)
		if kw['shell']:
			Logs.debug('runner: (shell) %s'%cmd)
		else:
			Logs.debug('runner: (exec) %s'%Utils.list2cmdline(cmd))
		Logs.debug('runner_env: kw=%s'%kw)
		if self.logger:
			self.logger.info(cmd)
		if'stdout'not in kw:
			kw['stdout']=subprocess.PIPE
		if'stderr'not in kw:
			kw['stderr']=subprocess.PIPE
		if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]):
			raise Errors.WafError("Program %s not found!"%cmd[0])
		try:
			if kw['stdout']or kw['stderr']:
				p=subprocess.Popen(cmd,**kw)
				(out,err)=p.communicate()
				ret=p.returncode
			else:
				out,err=(None,None)
				ret=subprocess.Popen(cmd,**kw).wait()
		except Exception ,e:
			raise Errors.WafError('Execution failure: %s'%str(e),ex=e)
开发者ID:hwyuan,项目名称:repo-ng-redis,代码行数:28,代码来源:Context.py

示例3: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
	def exec_command(self,cmd,**kw):
		subprocess=Utils.subprocess
		kw['shell']=isinstance(cmd,str)
		# FIXME: hacky solution to fix PIC-PIE-conflict
		if '-shared' in cmd:
			Logs.debug('runner: old %r'%(cmd,))
			cmd = [x for x in cmd if x != '-fPIE' and x != '-pie']
		Logs.debug('runner: %r',cmd)
		Logs.debug('runner_env: kw=%s',kw)
		if self.logger:
			self.logger.info(cmd)
		if'stdout'not in kw:
			kw['stdout']=subprocess.PIPE
		if'stderr'not in kw:
			kw['stderr']=subprocess.PIPE
		if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]):
			raise Errors.WafError('Program %s not found!'%cmd[0])
		wargs={}
		if'timeout'in kw:
			if kw['timeout']is not None:
				wargs['timeout']=kw['timeout']
			del kw['timeout']
		if'input'in kw:
			if kw['input']:
				wargs['input']=kw['input']
				kw['stdin']=subprocess.PIPE
			del kw['input']
		if'cwd'in kw:
			if not isinstance(kw['cwd'],str):
				kw['cwd']=kw['cwd'].abspath()
		try:
			ret,out,err=Utils.run_process(cmd,kw,wargs)
		except Exception ,e:
			raise Errors.WafError('Execution failure: %s'%str(e),ex=e),None,sys.exc_info()[2]
开发者ID:allencubie,项目名称:lib,代码行数:36,代码来源:Context.py

示例4: cmd_and_log

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
	def cmd_and_log(self,cmd,**kw):
		subprocess=Utils.subprocess
		kw['shell']=isinstance(cmd,str)
		Logs.debug('runner: %r'%(cmd,))
		if'quiet'in kw:
			quiet=kw['quiet']
			del kw['quiet']
		else:
			quiet=None
		if'output'in kw:
			to_ret=kw['output']
			del kw['output']
		else:
			to_ret=STDOUT
		if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]):
			raise Errors.WafError("Program %s not found!"%cmd[0])
		kw['stdout']=kw['stderr']=subprocess.PIPE
		if quiet is None:
			self.to_log(cmd)
		wargs={}
		if'timeout'in kw:
			if kw['timeout']is not None:
				wargs['timeout']=kw['timeout']
			del kw['timeout']
		if'input'in kw:
			if kw['input']:
				wargs['input']=kw['input']
				kw['stdin']=Utils.subprocess.PIPE
			del kw['input']
		try:
			p=subprocess.Popen(cmd,**kw)
			(out,err)=p.communicate(**wargs)
		except Exception ,e:
			raise Errors.WafError('Execution failure: %s'%str(e),ex=e)
开发者ID:hakiri,项目名称:sdn-ns-3,代码行数:36,代码来源:Context.py

示例5: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
	def exec_command(self, cmd, **kw):
		"""
		Execute a command and return the exit status. If the context has the attribute 'log',
		capture and log the process stderr/stdout for logging purposes::

			def run(tsk):
				ret = tsk.generator.bld.exec_command('touch foo.txt')
				return ret

		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
		"""
		subprocess = Utils.subprocess
		kw['shell'] = isinstance(cmd, str)
		Logs.debug('runner: %r' % cmd)
		Logs.debug('runner_env: kw=%s' % kw)

		if self.logger:
			self.logger.info(cmd)

		if 'stdout' not in kw:
			kw['stdout'] = subprocess.PIPE
		if 'stderr' not in kw:
			kw['stderr'] = subprocess.PIPE

		if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]):
			raise Errors.WafError("Program %s not found!" % cmd[0])

		try:
			if kw['stdout'] or kw['stderr']:
				p = subprocess.Popen(cmd, **kw)
				(out, err) = p.communicate()
				ret = p.returncode
			else:
				out, err = (None, None)
				ret = subprocess.Popen(cmd, **kw).wait()
		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')
			if self.logger:
				self.logger.debug('out: %s' % out)
			else:
				Logs.info(out, extra={'stream':sys.stdout, 'c1': ''})
		if err:
			if not isinstance(err, str):
				err = err.decode(sys.stdout.encoding or 'iso8859-1')
			if self.logger:
				self.logger.error('err: %s' % err)
			else:
				Logs.info(err, extra={'stream':sys.stderr, 'c1': ''})

		return ret
开发者ID:AleemDev,项目名称:waf,代码行数:60,代码来源:Context.py

示例6: cmd_and_log

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
 def cmd_and_log(self, cmd, **kw):
     subprocess = Utils.subprocess
     kw["shell"] = isinstance(cmd, str)
     Logs.debug("runner: %r", cmd)
     if "quiet" in kw:
         quiet = kw["quiet"]
         del kw["quiet"]
     else:
         quiet = None
     if "output" in kw:
         to_ret = kw["output"]
         del kw["output"]
     else:
         to_ret = STDOUT
     if Logs.verbose and not kw["shell"] and not Utils.check_exe(cmd[0]):
         raise Errors.WafError("Program %r not found!" % cmd[0])
     kw["stdout"] = kw["stderr"] = subprocess.PIPE
     if quiet is None:
         self.to_log(cmd)
     wargs = {}
     if "timeout" in kw:
         if kw["timeout"] is not None:
             wargs["timeout"] = kw["timeout"]
         del kw["timeout"]
     if "input" in kw:
         if kw["input"]:
             wargs["input"] = kw["input"]
             kw["stdin"] = subprocess.PIPE
         del kw["input"]
     if "cwd" in kw:
         if not isinstance(kw["cwd"], str):
             kw["cwd"] = kw["cwd"].abspath()
     try:
         ret, out, err = Utils.run_process(cmd, kw, wargs)
     except Exception as e:
         raise Errors.WafError("Execution failure: %s" % str(e), ex=e)
     if not isinstance(out, str):
         out = out.decode(sys.stdout.encoding or "iso8859-1")
     if not isinstance(err, str):
         err = err.decode(sys.stdout.encoding or "iso8859-1")
     if out and quiet != STDOUT and quiet != BOTH:
         self.to_log("out: %s" % out)
     if err and quiet != STDERR and quiet != BOTH:
         self.to_log("err: %s" % err)
     if ret:
         e = Errors.WafError("Command %r returned %r" % (cmd, ret))
         e.returncode = ret
         e.stderr = err
         e.stdout = out
         raise e
     if to_ret == BOTH:
         return (out, err)
     elif to_ret == STDERR:
         return err
     return out
开发者ID:Gnurou,项目名称:glmark2,代码行数:57,代码来源:Context.py

示例7: cmd_and_log

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
	def cmd_and_log(self,cmd,**kw):
		subprocess=Utils.subprocess
		kw['shell']=isinstance(cmd,str)
		Logs.debug('runner: %r'%(cmd,))
		if'quiet'in kw:
			quiet=kw['quiet']
			del kw['quiet']
		else:
			quiet=None
		if'output'in kw:
			to_ret=kw['output']
			del kw['output']
		else:
			to_ret=STDOUT
		if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]):
			raise Errors.WafError("Program %s not found!"%cmd[0])
		kw['stdout']=kw['stderr']=subprocess.PIPE
		if quiet is None:
			self.to_log(cmd)
		wargs={}
		if'timeout'in kw:
			if kw['timeout']is not None:
				wargs['timeout']=kw['timeout']
			del kw['timeout']
		if'input'in kw:
			if kw['input']:
				wargs['input']=kw['input']
				kw['stdin']=subprocess.PIPE
			del kw['input']
		try:
			p=subprocess.Popen(cmd,**kw)
			(out,err)=p.communicate(**wargs)
		except Exception as e:
			raise Errors.WafError('Execution failure: %s'%str(e),ex=e)
		if not isinstance(out,str):
			out=out.decode(sys.stdout.encoding or'iso8859-1')
		if not isinstance(err,str):
			err=err.decode(sys.stdout.encoding or'iso8859-1')
		if out and quiet!=STDOUT and quiet!=BOTH:
			self.to_log('out: %s'%out)
		if err and quiet!=STDERR and quiet!=BOTH:
			self.to_log('err: %s'%err)
		if p.returncode:
			e=Errors.WafError('Command %r returned %r'%(cmd,p.returncode))
			e.returncode=p.returncode
			e.stderr=err
			e.stdout=out
			raise e
		if to_ret==BOTH:
			return(out,err)
		elif to_ret==STDERR:
			return err
		return out
开发者ID:hgneng,项目名称:ekho,代码行数:55,代码来源:Context.py

示例8: find_program

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
def find_program(self,filename,**kw):
	exts=kw.get('exts',Utils.is_win32 and'.exe,.com,.bat,.cmd'or',.sh,.pl,.py')
	environ=kw.get('environ',getattr(self,'environ',os.environ))
	ret=''
	filename=Utils.to_list(filename)
	msg=kw.get('msg',', '.join(filename))
	var=kw.get('var','')
	if not var:
		var=re.sub(r'[-.]','_',filename[0].upper())
	path_list=kw.get('path_list','')
	if path_list:
		path_list=Utils.to_list(path_list)
	else:
		path_list=environ.get('PATH','').split(os.pathsep)
	if var in environ:
		filename=environ[var]
		if os.path.isfile(filename):
			ret=[filename]
		else:
			ret=self.cmd_to_list(filename)
	elif self.env[var]:
		ret=self.env[var]
		ret=self.cmd_to_list(ret)
	else:
		if not ret:
			ret=self.find_binary(filename,exts.split(','),path_list)
		if not ret and Utils.winreg:
			ret=Utils.get_registry_app_path(Utils.winreg.HKEY_CURRENT_USER,filename)
		if not ret and Utils.winreg:
			ret=Utils.get_registry_app_path(Utils.winreg.HKEY_LOCAL_MACHINE,filename)
		ret=self.cmd_to_list(ret)
	if ret:
		if len(ret)==1:
			retmsg=ret[0]
		else:
			retmsg=ret
	else:
		retmsg=False
	self.msg("Checking for program '%s'"%msg,retmsg,**kw)
	if not kw.get('quiet',None):
		self.to_log('find program=%r paths=%r var=%r -> %r'%(filename,path_list,var,ret))
	if not ret:
		self.fatal(kw.get('errmsg','')or'Could not find the program %r'%filename)
	interpreter=kw.get('interpreter',None)
	if interpreter is None:
		if not Utils.check_exe(ret[0],env=environ):
			self.fatal('Program %r is not executable'%ret)
		self.env[var]=ret
	else:
		self.env[var]=self.env[interpreter]+ret
	return ret
开发者ID:raystubbs,项目名称:NMSU-BigData-REU-NDN-Access-Control-Simulation,代码行数:53,代码来源:Configure.py

示例9: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
	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)
		if self.logger:
			self.logger.info(cmd)
		if'stdout'not in kw:
			kw['stdout']=subprocess.PIPE
		if'stderr'not in kw:
			kw['stderr']=subprocess.PIPE
		if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]):
			raise Errors.WafError("Program %s not found!"%cmd[0])
		wargs={}
		if'timeout'in kw:
			if kw['timeout']is not None:
				wargs['timeout']=kw['timeout']
			del kw['timeout']
		if'input'in kw:
			if kw['input']:
				wargs['input']=kw['input']
				kw['stdin']=subprocess.PIPE
			del kw['input']
		try:
			if kw['stdout']or kw['stderr']:
				p=subprocess.Popen(cmd,**kw)
				(out,err)=p.communicate(**wargs)
				ret=p.returncode
			else:
				out,err=(None,None)
				ret=subprocess.Popen(cmd,**kw).wait(**wargs)
		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')
			if self.logger:
				self.logger.debug('out: %s'%out)
			else:
				Logs.info(out,extra={'stream':sys.stdout,'c1':''})
		if err:
			if not isinstance(err,str):
				err=err.decode(sys.stdout.encoding or'iso8859-1')
			if self.logger:
				self.logger.error('err: %s'%err)
			else:
				Logs.info(err,extra={'stream':sys.stderr,'c1':''})
		return ret
开发者ID:hgneng,项目名称:ekho,代码行数:50,代码来源:Context.py

示例10: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
 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)
     if self.logger:
         self.logger.info(cmd)
     if "stdout" not in kw:
         kw["stdout"] = subprocess.PIPE
     if "stderr" not in kw:
         kw["stderr"] = subprocess.PIPE
     if Logs.verbose and not kw["shell"] and not Utils.check_exe(cmd[0]):
         raise Errors.WafError("Program %s not found!" % cmd[0])
     wargs = {}
     if "timeout" in kw:
         if kw["timeout"] is not None:
             wargs["timeout"] = kw["timeout"]
         del kw["timeout"]
     if "input" in kw:
         if kw["input"]:
             wargs["input"] = kw["input"]
             kw["stdin"] = subprocess.PIPE
         del kw["input"]
     if "cwd" in kw:
         if not isinstance(kw["cwd"], str):
             kw["cwd"] = kw["cwd"].abspath()
     try:
         ret, out, err = Utils.run_process(cmd, kw, wargs)
     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")
         if self.logger:
             self.logger.debug("out: %s", out)
         else:
             Logs.info(out, extra={"stream": sys.stdout, "c1": ""})
     if err:
         if not isinstance(err, str):
             err = err.decode(sys.stdout.encoding or "iso8859-1")
         if self.logger:
             self.logger.error("err: %s" % err)
         else:
             Logs.info(err, extra={"stream": sys.stderr, "c1": ""})
     return ret
开发者ID:Gnurou,项目名称:glmark2,代码行数:47,代码来源:Context.py

示例11: cmd_and_log

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
	def cmd_and_log(self,cmd,**kw):
		subprocess=Utils.subprocess
		kw['shell']=isinstance(cmd,str)
		Logs.debug('runner: %r',cmd)
		if'quiet'in kw:
			quiet=kw['quiet']
			del kw['quiet']
		else:
			quiet=None
		if'output'in kw:
			to_ret=kw['output']
			del kw['output']
		else:
			to_ret=STDOUT
		if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]):
			raise Errors.WafError('Program %r not found!'%cmd[0])
		kw['stdout']=kw['stderr']=subprocess.PIPE
		if quiet is None:
			self.to_log(cmd)
		wargs={}
		if'timeout'in kw:
			if kw['timeout']is not None:
				wargs['timeout']=kw['timeout']
			del kw['timeout']
		if'input'in kw:
			if kw['input']:
				wargs['input']=kw['input']
				kw['stdin']=subprocess.PIPE
			del kw['input']
		if'cwd'in kw:
			if not isinstance(kw['cwd'],str):
				kw['cwd']=kw['cwd'].abspath()
		try:
			ret,out,err=Utils.run_process(cmd,kw,wargs)
		except Exception ,e:
			raise Errors.WafError('Execution failure: %s'%str(e),ex=e),None,sys.exc_info()[2]
开发者ID:allencubie,项目名称:lib,代码行数:38,代码来源:Context.py

示例12: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
    def exec_command(self, cmd, **kw):
        """
		Runs an external process and returns the exit status::

			def run(tsk):
				ret = tsk.generator.bld.exec_command('touch foo.txt')
				return ret

		If the context has the attribute 'log', then captures and logs the process stderr/stdout.
		Unlike :py:meth:`waflib.Context.Context.cmd_and_log`, this method does not return the
		stdout/stderr values captured.

		:param cmd: command argument for subprocess.Popen
		:type cmd: string or list
		:param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate.
		:type kw: dict
		:returns: process exit status
		:rtype: integer
		"""
        subprocess = Utils.subprocess
        kw["shell"] = isinstance(cmd, str)
        Logs.debug("runner: %r", cmd)
        Logs.debug("runner_env: kw=%s", kw)

        if self.logger:
            self.logger.info(cmd)

        if "stdout" not in kw:
            kw["stdout"] = subprocess.PIPE
        if "stderr" not in kw:
            kw["stderr"] = subprocess.PIPE

        if Logs.verbose and not kw["shell"] and not Utils.check_exe(cmd[0]):
            raise Errors.WafError("Program %s not found!" % cmd[0])

        cargs = {}
        if "timeout" in kw:
            if kw["timeout"] is not None:
                if kw["shell"]:
                    Logs.warn("Shell commands cannot timeout %r", cmd)
            del kw["timeout"]
        if "input" in kw:
            if kw["input"]:
                cargs["input"] = kw["input"]
                kw["stdin"] = subprocess.PIPE
            del kw["input"]

        if "cwd" in kw:
            if not isinstance(kw["cwd"], str):
                kw["cwd"] = kw["cwd"].abspath()

        try:
            ret, out, err = Utils.run_process(cmd, kw, cargs)
        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")
            if self.logger:
                self.logger.debug("out: %s", out)
            else:
                Logs.info(out, extra={"stream": sys.stdout, "c1": ""})
        if err:
            if not isinstance(err, str):
                err = err.decode(sys.stdout.encoding or "iso8859-1")
            if self.logger:
                self.logger.error("err: %s" % err)
            else:
                Logs.info(err, extra={"stream": sys.stderr, "c1": ""})

        return ret
开发者ID:thmo,项目名称:waf,代码行数:74,代码来源:Context.py

示例13: cmd_and_log

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
	def cmd_and_log(self, cmd, **kw):
		"""
		Executes a process and returns stdout/stderr if the execution is successful.
		An exception is thrown when the exit status is non-0. In that case, both stderr and stdout
		will be bound to the WafError object (configuration tests)::

			def configure(conf):
				out = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.STDOUT, quiet=waflib.Context.BOTH)
				(out, err) = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.BOTH)
				(out, err) = conf.cmd_and_log(cmd, input='\\n'.encode(), output=waflib.Context.STDOUT)
				try:
					conf.cmd_and_log(['which', 'someapp'], output=waflib.Context.BOTH)
				except Errors.WafError as e:
					print(e.stdout, e.stderr)

		:param cmd: args for subprocess.Popen
		:type cmd: list or string
		:param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate.
		:type kw: dict
		:returns: a tuple containing the contents of stdout and stderr
		:rtype: string
		:raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process
		:raises: :py:class:`waflib.Errors.WafError` in case of execution failure; stdout/stderr/returncode are bound to the exception object
		"""
		subprocess = Utils.subprocess
		kw['shell'] = isinstance(cmd, str)
		self.log_command(cmd, kw)

		quiet = kw.pop('quiet', None)
		to_ret = kw.pop('output', STDOUT)

		if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]):
			raise Errors.WafError('Program %r not found!' % cmd[0])

		kw['stdout'] = kw['stderr'] = subprocess.PIPE
		if quiet is None:
			self.to_log(cmd)

		cargs = {}
		if 'timeout' in kw:
			if sys.hexversion >= 0x3030000:
				cargs['timeout'] = kw['timeout']
				if not 'start_new_session' in kw:
					kw['start_new_session'] = True
			del kw['timeout']
		if 'input' in kw:
			if kw['input']:
				cargs['input'] = kw['input']
				kw['stdin'] = subprocess.PIPE
			del kw['input']

		if 'cwd' in kw:
			if not isinstance(kw['cwd'], str):
				kw['cwd'] = kw['cwd'].abspath()

		encoding = kw.pop('decode_as', default_encoding)

		try:
			ret, out, err = Utils.run_process(cmd, kw, cargs)
		except Exception as e:
			raise Errors.WafError('Execution failure: %s' % str(e), ex=e)

		if not isinstance(out, str):
			out = out.decode(encoding, errors='replace')
		if not isinstance(err, str):
			err = err.decode(encoding, errors='replace')

		if out and quiet != STDOUT and quiet != BOTH:
			self.to_log('out: %s' % out)
		if err and quiet != STDERR and quiet != BOTH:
			self.to_log('err: %s' % err)

		if ret:
			e = Errors.WafError('Command %r returned %r' % (cmd, ret))
			e.returncode = ret
			e.stderr = err
			e.stdout = out
			raise e

		if to_ret == BOTH:
			return (out, err)
		elif to_ret == STDERR:
			return err
		return out
开发者ID:fedepell,项目名称:waf,代码行数:86,代码来源:Context.py

示例14: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
	def exec_command(self, cmd, **kw):
		"""
		Runs an external process and returns the exit status::

			def run(tsk):
				ret = tsk.generator.bld.exec_command('touch foo.txt')
				return ret

		If the context has the attribute 'log', then captures and logs the process stderr/stdout.
		Unlike :py:meth:`waflib.Context.Context.cmd_and_log`, this method does not return the
		stdout/stderr values captured.

		:param cmd: command argument for subprocess.Popen
		:type cmd: string or list
		:param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate.
		:type kw: dict
		:returns: process exit status
		:rtype: integer
		:raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process
		:raises: :py:class:`waflib.Errors.WafError` in case of execution failure
		"""
		subprocess = Utils.subprocess
		kw['shell'] = isinstance(cmd, str)
		self.log_command(cmd, kw)

		if self.logger:
			self.logger.info(cmd)

		if 'stdout' not in kw:
			kw['stdout'] = subprocess.PIPE
		if 'stderr' not in kw:
			kw['stderr'] = subprocess.PIPE

		if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]):
			raise Errors.WafError('Program %s not found!' % cmd[0])

		cargs = {}
		if 'timeout' in kw:
			if sys.hexversion >= 0x3030000:
				cargs['timeout'] = kw['timeout']
				if not 'start_new_session' in kw:
					kw['start_new_session'] = True
			del kw['timeout']
		if 'input' in kw:
			if kw['input']:
				cargs['input'] = kw['input']
				kw['stdin'] = subprocess.PIPE
			del kw['input']

		if 'cwd' in kw:
			if not isinstance(kw['cwd'], str):
				kw['cwd'] = kw['cwd'].abspath()

		encoding = kw.pop('decode_as', default_encoding)

		try:
			ret, out, err = Utils.run_process(cmd, kw, cargs)
		except Exception as e:
			raise Errors.WafError('Execution failure: %s' % str(e), ex=e)

		if out:
			if not isinstance(out, str):
				out = out.decode(encoding, errors='replace')
			if self.logger:
				self.logger.debug('out: %s', out)
			else:
				Logs.info(out, extra={'stream':sys.stdout, 'c1': ''})
		if err:
			if not isinstance(err, str):
				err = err.decode(encoding, errors='replace')
			if self.logger:
				self.logger.error('err: %s' % err)
			else:
				Logs.info(err, extra={'stream':sys.stderr, 'c1': ''})

		return ret
开发者ID:fedepell,项目名称:waf,代码行数:78,代码来源:Context.py

示例15: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import check_exe [as 别名]
	def exec_command(self, cmd, **kw):
		"""
		Runs an external process and returns the exit status::

			def run(tsk):
				ret = tsk.generator.bld.exec_command('touch foo.txt')
				return ret

		If the context has the attribute 'log', then captures and logs the process stderr/stdout.
		Unlike :py:meth:`waflib.Context.Context.cmd_and_log`, this method does not return the
		stdout/stderr values captured.

		:param cmd: command argument for subprocess.Popen
		:type cmd: string or list
		:param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate.
		:type kw: dict
		:returns: process exit status
		:rtype: integer
		"""
		subprocess = Utils.subprocess
		kw['shell'] = isinstance(cmd, str)
		Logs.debug('runner: %r', cmd)
		Logs.debug('runner_env: kw=%s', kw)

		if self.logger:
			self.logger.info(cmd)

		if 'stdout' not in kw:
			kw['stdout'] = subprocess.PIPE
		if 'stderr' not in kw:
			kw['stderr'] = subprocess.PIPE

		if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]):
			raise Errors.WafError('Program %s not found!' % cmd[0])

		wargs = {}
		if 'timeout' in kw:
			if kw['timeout'] is not None:
				wargs['timeout'] = kw['timeout']
			del kw['timeout']
		if 'input' in kw:
			if kw['input']:
				wargs['input'] = kw['input']
				kw['stdin'] = subprocess.PIPE
			del kw['input']

		if 'cwd' in kw:
			if not isinstance(kw['cwd'], str):
				kw['cwd'] = kw['cwd'].abspath()

		try:
			ret, out, err = Utils.run_process(cmd, kw, wargs)
		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')
			if self.logger:
				self.logger.debug('out: %s', out)
			else:
				Logs.info(out, extra={'stream':sys.stdout, 'c1': ''})
		if err:
			if not isinstance(err, str):
				err = err.decode(sys.stdout.encoding or 'iso8859-1')
			if self.logger:
				self.logger.error('err: %s' % err)
			else:
				Logs.info(err, extra={'stream':sys.stderr, 'c1': ''})

		return ret
开发者ID:Whyki,项目名称:waf,代码行数:73,代码来源:Context.py


注:本文中的waflib.Utils.check_exe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。