def run_command(command, timeout=15): """Executes a shell command and returns the output. Args: command (str): The shell command to execute. timeout (int): The number of seconds to wait before timing out. Returns: tuple: A tuple containing the return code and output of the command. """ process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True ) try: stdout, stderr = process.communicate(timeout=timeout) except subprocess.TimeoutExpired: process.kill() raise TimeoutError(f"Command {command} timed out after {timeout} seconds.") result = stderr.decode('utf-8') if process.returncode else stdout.decode('utf-8') return process.returncode, result