simplify stdout redirection for pdftk

This commit is contained in:
Jean-Francois Dockes 2020-11-25 17:54:06 +01:00
parent 6d59b4c433
commit 33725fd02c

View File

@ -210,15 +210,16 @@ class PDFExtractor:
try: try:
vacuumdir(tmpdir) vacuumdir(tmpdir)
# Note: the java version of pdftk sometimes/often fails # Note: the java version of pdftk sometimes/often fails
# here with writing to stdout: "Error occurred during # here with writing to stdout:
# initialization of VM". Maybe unsufficient resources when # Error occurred during initialization of VM
# execd from Python ? In any case, the important thing is # Could not allocate metaspace: 1073741824 bytes
# to discard the output, until we fix the error or # Maybe unsufficient resources when started from Python ?
# preferably find a way to do it with poppler... # In any case, the important thing is to discard the
with open(os.devnull, 'w') as FNULL: # output, until we fix the error or preferably find a way
subprocess.check_call( # to do it with poppler...
[self.pdftk, self.filename, "unpack_files", "output", subprocess.check_call(
tmpdir], stdout=FNULL) [self.pdftk, self.filename, "unpack_files", "output",
tmpdir], stdout=sys.stderr)
self.attachlist = sorted(os.listdir(tmpdir)) self.attachlist = sorted(os.listdir(tmpdir))
return True return True
except Exception as e: except Exception as e: