Michael Michael - 4 months ago 9
Python Question

Getting python to run an application when the application needs an input file

import subprocess
subprocess.call(['C:\\Users\michael\\Desktop\\Test\\pdftotext'])


pdftotext is the application that will run if I use this ^ code. This works fine, however, I'm trying to find a way to run pdftotext that includes the pdf's file name which pdftotext uses to convert it into a text file.

Note this is NOT a question about pdftotext.

When I use cmd in windows to run this I simply type pdftotext fileName.pdf and it converts the pdf file into a text file, no problem. Now I want to do something equivalent with Python.

I changed it to this, but it doesn't work. I'm told "The system cannot find the file specified" and I've put pdftotext in the src file along with filename.pdf

import subprocess
subprocess.call(['C:\\Users\michael\\Desktop\\Test\\pdftotext', 'filename.pdf'])

Answer

subprocess.call takes an iterable where the first item is the executable and the following are switches and parameters.

This means you need to change the above to this:

import subprocess
subprocess.call(['C:\\Users\michael\\Desktop\\Test\\pdftotext', 'filename.pdf'])