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