Skip to content

Commit

Permalink
capture output from subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
cccs-rs committed Jun 9, 2022
1 parent 294b168 commit d0ae4d2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions document_preview/document_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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]

Expand Down

0 comments on commit d0ae4d2

Please sign in to comment.