From d0ae4d29ade6b6c993cebc63ebedd375703ab394 Mon Sep 17 00:00:00 2001 From: cccs-rs Date: Thu, 9 Jun 2022 17:42:21 +0000 Subject: [PATCH] capture output from subprocess --- document_preview/document_preview.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/document_preview/document_preview.py b/document_preview/document_preview.py index d13bb9f..15306b4 100644 --- a/document_preview/document_preview.py +++ b/document_preview/document_preview.py @@ -28,9 +28,9 @@ def stop(self): self.log.debug("Document preview service ended") def libreoffice_conversion(self, file, convert_to="pdf"): - subprocess.check_output( - f"libreoffice --headless --convert-to {convert_to} --outdir " + self.working_directory + " " + file, - shell=True) + subprocess.run(["libreoffice", "--headless", + "--convert-to", convert_to, + "--outdir", self.working_directory, file], capture_output=True) converted_file = [s for s in os.listdir(self.working_directory) if f".{convert_to}" in s][0] @@ -40,9 +40,11 @@ def libreoffice_conversion(self, file, convert_to="pdf"): return (False, None) def office_conversion(self, file, orientation="portrait", page_range_end=2): - subprocess.check_output( - f"unoconv -f pdf -e PageRange=1-{page_range_end} -P PaperOrientation={orientation} -P PaperFormat=A3 -o {self.working_directory}/ {file}", - shell=True) + subprocess.run(["unoconv", "-f", "pdf", + "-e", f"PageRange=1-{page_range_end}", + "-P", f"PaperOrientation={orientation}", + "-P", "PaperFormat=A3", + "-o", f"{self.working_directory}/", file], capture_output=True) converted_file = [s for s in os.listdir(self.working_directory) if f".pdf" in s]