Subprocess Popen and PIPE in Python
-
11-09-2019 - |
Question
The following code prints an empty line as an output which is false. The problem is not in the permissions, since I tested the command with 777 permissions for the pdf -file. How can you fix the command to give a right output?
import subprocess
from subprocess import PIPE, Popen
output = Popen(['pdftotext', '/home/aal/Desktop/lkn_pdf/appa.pdf'], stdout=PIPE).communicate()[0]
Solution
pdftotext creates a file by default. To send the result to standard output, use:
pdftotext file.pdf -
or in Python:
output = Popen(['pdftotext', '/home/aal/Desktop/lkn_pdf/appa.pdf', '-'], stdout=PIPE).communicate()[0]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow