views:

72

answers:

1

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?

+1  A: 

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.

abeyer
wouldn't this be ruled out since i could get it to work on the python interpreter?
hatorade
Are you just inheriting the parent's $PATH? If so then maybe something changes it before the subprocess.call(), which isn't happening when you just do the call from the repl.
abeyer
yes, i am. well, implicitly i must be since i'm not doing anything to $PATH knowingly.
hatorade
newb unix question time: where is the best place to look for pdftotext, or how should i go about finding it?
hatorade
type 'which pdftotext' in the shell to get the full path
abeyer
thanks. i'll try it out now
hatorade
unfortunately, that did not fix it. same error.
hatorade