def get_bash_output(cmd, strip=False, stderr=subprocess.STDOUT, stdin=False): try: output = (subprocess.check_output( bash_c().split() + [cmd], stderr=stderr, stdin=subprocess.PIPE if stdin else None, ).decode().strip()) except subprocess.CalledProcessError: output = None return output if not strip or not output else output.strip()
def get_argv(self, shell=False): """ Get array of argv's. :param bool shell: if True, returns the argv of a process that will invoke a shell running the command sequence """ if shell: return tuple(bash_c().split()) + (self.serialize(),) def safe_get_argv(obj): try: func = obj.get_argv except AttributeError: result = obj else: result = func() return tuple(map(str, result)) return tuple(map(safe_get_argv, self.commands))