From 66e9aabf219d2b93bb951218306e9b995967148a Mon Sep 17 00:00:00 2001 From: zhu0823 Date: Wed, 19 Jun 2024 11:36:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eshell=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker_events.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docker_events.py b/docker_events.py index b36d5cd..c40c4b0 100644 --- a/docker_events.py +++ b/docker_events.py @@ -82,6 +82,17 @@ def handle_event(event, names, valid_events): if event['status'] in list(event_model.keys()): logger.debug('捕获事件:', name, event.get('status'), event_model[event["status"]]) handing_event = True - subprocess.run(f'chmod 777 {event_model[event["status"]]}', shell=True) - subprocess.run(f'sh {event_model[event["status"]]}', shell=True) + run_command(f'chmod 777 {event_model[event["status"]]}') + run_command(f'sh {event_model[event["status"]]}') handing_event = False + + +def run_command(command): + """运行命令""" + try: + result = subprocess.run(command, shell=True, capture_output=True, text=True) + logger.debug('Command Output: %s', result.stdout) + if result.stderr: + logger.error("Command Error: %s", result.stderr) + except Exception as e: + logger.error("Command Exception: %s", str(e))