def run_process(args, logger=None, initial_env=None): def log(buffer, checkNewLine=False): endsWithNewLine = False if buffer.endswith('\n'): endsWithNewLine = True if checkNewLine and buffer.find('\n') == -1: return buffer lines = buffer.splitlines() buffer = '' if checkNewLine and not endsWithNewLine: buffer = lines[-1] lines = lines[:-1] for line in lines: if not logger is None: logger.info(line.rstrip('\r')) else: print(line.rstrip('\r')) return buffer log("Running process: {0}".format(" ".join([(" " in x and '"{0}"'.format(x) or x) for x in args]))) if sys.platform != "win32": try: spawn(args) return 0 except DistutilsExecError: return -1 shell = False if sys.platform == "win32": shell = True if initial_env is None: initial_env = os.environ proc = popenasync.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=1, shell=shell, env=initial_env) log_buffer = None while proc.poll() is None: log_buffer = log(proc.read_async(wait=0.1, e=0)) if log_buffer: log(log_buffer) proc.wait() return proc.returncode
def getProperty(self, prop_name): cmd = [self._qmake_path, "-query", prop_name] proc = popenasync.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=1, shell=False) prop = '' while proc.poll() is None: prop += proc.read_async(wait=0.1, e=0) proc.wait() if proc.returncode != 0: return None return prop.strip()
def run_process(args, logger=None): def log(buffer, checkNewLine): endsWithNewLine = False if buffer.endswith('\n'): endsWithNewLine = True if checkNewLine and buffer.find('\n') == -1: return buffer lines = buffer.splitlines() buffer = '' if checkNewLine and not endsWithNewLine: buffer = lines[-1] lines = lines[:-1] for line in lines: if not logger is None: logger.info(line.rstrip('\r')) else: print(line.rstrip('\r')) return buffer shell = False if sys.platform == "win32": shell = True proc = popenasync.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=1, shell=shell, env=os.environ) log_buffer = None while proc.poll() is None: log_buffer = log(proc.read_async(wait=0.1, e=0), False) if log_buffer: log(log_buffer, False) proc.wait() return proc.returncode