Question

i have a python script which keeps crashing on:

subprocess.call(["pdftotext", pdf_filename])

the error being:

OSError: [Errno 2] No such file or directory

the absolute path to the filename (which i am storing in a log file as i debug) is fine; on the command line, if i type pdftotext <pdf_filename_goes_here> it works for any of the alledgedly bad file names. but when called using subprocess in python i keep getting that error.

what is going on???

also, i tried on the python interpreter, and it worked!

>>> import subprocess
>>> subprocess.call(["pdftotext", "/path/to/file/test.pdf"])
0
>>> 

update: just to make it known to everyone, i also tried:

subprocess.call(["/usr/bin/pdftotext", "/path/to/file/test.pdf"])

which also gave the same error. and ive used /usr/bin/pdftotext test.pdf directly and it worked so i know that's the correct path to the pdftotext executable. any other suggestions?

Was it helpful?

Solution

You'll also get that error if it can't find the executable on path...try using a full path to pdftotext as well, and look at how the $PATH for subprocess.call is set.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top