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


Python Utils.run_process方法代码示例

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


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

示例1: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import run_process [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

示例2: cmd_and_log

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import run_process [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

示例3: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import run_process [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

示例4: cmd_and_log

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import run_process [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

示例5: cmd_and_log

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import run_process [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

示例6: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import run_process [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

示例7: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import run_process [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

示例8: cmd_and_log

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import run_process [as 别名]
    def cmd_and_log(self, cmd, **kw):
        """
		Executes a proces 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::

			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 Exception 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: 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; stdout/stderr/returncode are bound to the exception object
		"""
        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)

        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 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:thmo,项目名称:waf,代码行数:92,代码来源:Context.py

示例9: exec_command

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import run_process [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


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