Execute cmd and capture stdout and stderr

    :param cmd: command to be executed
    :return: (stdout, stderr)
173022
def sys_call(cmd):
    
    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
    return p.stdout.readlines(), p.stderr.readlines()
819029
def succ(cmd, check_stderr=True, stdout=None, stderr=None):
    '''
    
    '''
    code, out, err = run(cmd)

    # Because we're raising error, sometimes we want to process stdout/stderr after catching error
    # so we're copying these outputs if required
    if stdout is not None:
        stdout[:] = out
    if stderr is not None:
        stderr[:] = err

    if code != 0:
        for l in out:
            print(l)
    assert code == 0, 'Return: {} {}\nStderr: {}'.format(code, cmd, err)
    if check_stderr:
        assert err == [], 'Error: {} {}'.format(err, code)
    return code, out, err
1095274
def _run_cmd(cmd):
    """"""
    if not os.path.exists(cmd[0]):
        cmd[0] = shutil.which(cmd[0])
        assert cmd[0] is not None

    shebang_parts = parseshebang.parse(cmd[0])

    proc = subprocess.Popen(shebang_parts + cmd,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate()
    return {
        "stdout": stdout,
        "stderr": stderr,
        "code": proc.returncode
    }
730873
def _execute(self, command, stdin=None, stdout=subprocess.PIPE):
        
        process = subprocess.Popen(command, shell=True, cwd=self.root_path, stdin=stdin, stdout=stdout)
        return (process.wait(), None if stdout is not subprocess.PIPE else process.communicate()[0].decode('utf-8'))
993173
function run(cmd) {
        return function (callback, options) {
            grunt.verbose.or.ok("Executing " + cmd);
            exec(cmd, options || {}, function (error, stdout, stderr) {
                if (error) {
                    grunt.fatal("'" + cmd + "' failed with :" + stderr);
                } else {
                    grunt.verbose.writeln("Result of " + cmd + ':\n' + stdout);
                    callback();
                }
            });
        };
    }
591907
def runCommandReturnOutput(cmd):
    
    splits = shlex.split(cmd)
    proc = subprocess.Popen(
        splits, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate()
    if proc.returncode != 0:
        raise subprocess.CalledProcessError(stdout, stderr)
    return stdout, stderr
774660
def ExecuteCmd(cmd, quiet=False):
  
  result = None
  if quiet:
    with open(os.devnull, "w") as fnull:
      result = subprocess.call(cmd, shell=True, stdout=fnull, stderr=fnull)
  else:
    result = subprocess.call(cmd, shell=True)
  return result
835227
def exec_cmd(self, cmd):
        '''
        
        '''
        cmd = self._cmd_str(cmd)

        logmsg = 'Executing command: {0}'.format(cmd)
        if self.passwd:
            logmsg = logmsg.replace(self.passwd, ('*' * 6))
        if 'decode("base64")' in logmsg or 'base64.b64decode(' in logmsg:
            log.debug('Executed SHIM command. Command logged to TRACE')
            log.trace(logmsg)
        else:
            log.debug(logmsg)

        ret = self._run_cmd(cmd)
        return ret
935129
function exec (cmd) {
  debug('executing cmd', cmd)
  child_process.exec(cmd, function (err, stdout, stderr) {
    debug('command completed')
  })
}
463008
def run_command_orig(cmd):
    
    process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = process.communicate()
    if process.returncode == 0:
        os.killpg(os.getpgid(pro.pid), signal.SIGTERM)
    else:
        raise BadRCError("Bad rc (%s) for cmd '%s': %s" % (process.returncode, cmd, stdout + stderr))
    return stdout
616268
def popen(self, cmd):
        
        process = Popen(cmd, shell=True, stdout=PIPE, env=self.env)
        stdoutdata, stderrdata = process.communicate()
        return process.returncode, stdoutdata
1344541
def execute_command(self, cmnd, *args, **options):
        ""
        args, options = self.preprocess_command(cmnd, *args, **options)
        return self.client.execute_command(cmnd, *args, **options)
1049427
def run(command):
    
    p = Popen(command.split(), stdout=PIPE, stderr=PIPE)
    (stdout, stderr) = p.communicate()
    return (p.returncode, [line.strip() for line in stdout.splitlines()],
            [line.strip() for line in stderr.splitlines()])
8693
def execute(cmd):
    """"""
    proc = Popen(cmd, stdout=PIPE)
    stdout, _ = proc.communicate()
    if proc.returncode != 0:
        raise CalledProcessError(proc.returncode, " ".join(cmd))

    return stdout.decode('utf8')
707785
def run(self, cmd=None):
		
		diagnostics.prefix.append(self.name)

		if not cmd:
			cmd = self.cmd

		stderr = os.path.abspath(self.name + '.log')
		self.args.append('2>>'+stderr)

		if self.pipe:
			self.args += ('|', self.pipe, '2>>'+stderr)

		# Write to a stdout file if it was set by the derived class.
		# Otherwise, stdout and stderr will be combined into the log file.
		if self.stdout:
			stdout = os.path.abspath(self.stdout)
			self.args.append('1>'+stdout)
			diagnostics.log('stdout', stdout)
		elif self.stdout_append:
			stdout = os.path.abspath(self.stdout_append)
			self.args.append('1>>'+stdout)
			diagnostics.log('stdout', stdout)
		else:
			self.args.append('1>>'+stderr)

		# Print timestamp to log
		open(stderr, 'a').write("[biolite] timestamp=%s\n" % utils.timestamp())
		diagnostics.log('log', stderr)

		cmd = ' '.join(chain(cmd, map(str, self.args)))
		diagnostics.log('command', cmd)

		start = time.time()
		save_cwd = os.getcwd()
		try:
			os.chdir(self.cwd)
			spawn_pid = os.spawnle(os.P_NOWAIT, self.shell, self.shell, '-c', cmd, self.env)
			wait_pid, retcode, rusage = os.wait4(spawn_pid, 0)
			if wait_pid != spawn_pid:
				utils.die("could not wait for process %d: got %d" % (spawn_pid, wait_pid))
			os.chdir(save_cwd)
		except OSError as e:
			utils.info(e)
			utils.die("could not run wrapper for command:\n%s" % cmd)
			#utils.failed_executable(exe, e)

		elapsed = time.time() - start
		retcode = os.WEXITSTATUS(retcode)

		if (self.return_ok is not None) and (self.return_ok != retcode):
			# Give some context to the non-zero return.
			if os.path.isfile(stderr):
				subprocess.call(['tail', '-3', stderr])
			utils.die("non-zero return (%d) from command:\n%s" % (retcode, cmd))

		# Log profile.
		diagnostics.prefix.append('profile')
		diagnostics.log('name', self.name)
		diagnostics.log('return', retcode)
		diagnostics.log('walltime', elapsed)
		diagnostics.log('usertime', rusage.ru_utime)
		diagnostics.log('systime', rusage.ru_stime)
		if config.uname == 'Darwin':
			diagnostics.log('maxrss', rusage.ru_maxrss / 1024)
		else:
			diagnostics.log('maxrss', rusage.ru_maxrss)
		diagnostics.prefix.pop()

		# Reverse any output patterns, since they will be matched against
		# program output from the last line backward.
		if self.output_patterns:
			self.output_patterns.reverse()

		diagnostics.log_program_output(stderr, self.output_patterns)
		diagnostics.prefix.pop()
959000
def popen(self, stdout, stderr):
        
        self.logger.info('Executing command: %s', self.command_str)
        return subprocess.Popen([self._executor_script], stdout=stdout, stderr=stderr)
621160
def execute_command(self, cmd):
        
        if self.input_mode:
            self.end_input(cmd)
            return
        if cmd.endswith('\n'):
            cmd = cmd[:-1]
        # cls command
        if cmd == 'cls':
            self.clear_terminal()
            return
        self.run_command(cmd)