From 70534a7cc1289172c4731daee2885d50fd6863db Mon Sep 17 00:00:00 2001 From: Jeremy Singer-Vine Date: Fri, 7 Jun 2024 11:38:07 -0400 Subject: [PATCH] Fix repair=True proc args (stderr being captured) --- pdfplumber/repair.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pdfplumber/repair.py b/pdfplumber/repair.py index 64f91dd..87ebd39 100644 --- a/pdfplumber/repair.py +++ b/pdfplumber/repair.py @@ -25,6 +25,7 @@ def _repair( repair_args = [ executable, + "-sstdout=%stderr", "-o", "-", "-sDEVICE=pdfwrite", @@ -41,14 +42,16 @@ def _repair( stdin = path_or_fp repair_args += ["-"] - stdout, stderr = subprocess.Popen( + proc = subprocess.Popen( repair_args, stdin=subprocess.PIPE if stdin else None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - ).communicate(stdin.read() if stdin else None) + ) - if len(stderr): + stdout, stderr = proc.communicate(stdin.read() if stdin else None) + + if proc.returncode: raise Exception(f"{stderr.decode('utf-8')}") return BytesIO(stdout)