Michael Michael - 1 year ago 55
Python Question

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

import subprocess

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 Source

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'])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download