From 8420b3471ab40605c146e4bb623c212a1f9fc546 Mon Sep 17 00:00:00 2001 From: William Jin Date: Thu, 26 Sep 2024 17:07:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E7=A8=8B=E5=BA=8F=20stdout=20?= =?UTF-8?q?=E5=86=99=E5=85=A5=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chyoso_toolkit_ui.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/chyoso_toolkit_ui.py b/chyoso_toolkit_ui.py index 30c9141..76e40c1 100644 --- a/chyoso_toolkit_ui.py +++ b/chyoso_toolkit_ui.py @@ -177,15 +177,17 @@ def run_ocr(image): "sudo", "-u", "tmfc", "/home/tmfc/miniconda3/envs/got/bin/python3", "/home/tmfc/apps/got-ocr/GOT/demo/run_ocr_2.0_crop.py", "--model-name", "/home/tmfc/apps/got-ocr/models/", - "--image-file", image_path, - "> /home/tmfc/apps/got-ocr/img.txt" + "--image-file", image_path ] + out_file = "/home/tmfc/apps/got-ocr/img.txt" try: - subprocess.run(command, check=True) + with open(out_file, 'w') as f: + result = subprocess.run(command, stdout=f, stderr=subprocess.PIPE, text=True) + except subprocess.CalledProcessError as e: return f"识别失败: {e}" - with open("/home/tmfc/apps/got-ocr/img.txt", 'r', encoding='utf-8') as f: + with open(out_file, 'r', encoding='utf-8') as f: content = f.read() return content