From 7b360d380c6fbb80d3a3d9baf1e8f654803a01ef Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 30 Apr 2025 15:03:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=9B=B4=E6=96=B0=E6=8C=87?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/system_updater/main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/system_updater/main.py b/plugins/system_updater/main.py index 7917ddc..1da9efe 100644 --- a/plugins/system_updater/main.py +++ b/plugins/system_updater/main.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import os import subprocess from loguru import logger from typing import Dict, Any, List, Optional, Tuple @@ -132,17 +133,23 @@ class SystemUpdaterPlugin(MessagePluginInterface): def _execute_system_update(self): """执行系统更新操作""" try: - # 调用 restart.sh 脚本进行系统更新 + # 使用相对路径调用 restart.sh 脚本 result = subprocess.run( - ["/home/liuwei/wechatbot/WeChatRobot/restart.sh"], # 指定脚本的实际路径 + ["./restart.sh"], # 使用相对路径 check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + cwd=os.path.join(os.path.dirname(__file__)) # 确保在当前目录执行 ) + + # 打印执行结果 logger.info(f"更新命令执行成功: {result.stdout.decode()}") + except subprocess.CalledProcessError as e: + # 如果 subprocess 执行出错,输出 stderr 信息 logger.error(f"执行更新命令时出错: {e.stderr.decode()}") except Exception as e: + # 捕获其他异常 logger.error(f"系统更新失败: {str(e)}")