INNER CODE UNIT · Python
run_command
ArcSurge/Termius-Pro-zh_CN · lang.py:248
def run_command(cmd, shell=False):
"""执行系统命令,失败时退出程序"""
if isinstance(cmd, list):
logging.debug(f"Running command: {' '.join(cmd)}")
else:
logging.debug(f"Running command: {cmd}")
try:
subprocess.run(cmd, shell=shell, check=True)
except subprocess.CalledProcessError as e:
logging.error(f"Command failed with exit code {e.returncode}: {' '.join(cmd) if isinstance(cmd, list) else cmd}")
sys.exit(1)
except FileNotFoundError:
logging.error(f"Command not found: {cmd}")
sys.exit(1)
except Exception as e:
logging.error(f"Unexpected error executing command: {e}")
sys.exit(1)