Python: Failing to open a file using os.system()
You can avoid (potential) problems with quoting, escaping, and so on, with subprocess
:
import subprocess
subprocess.call(['pdftk', '1.pdf', '2.pdf', 'cat', 'output', 'result.pdf'])
It's just as easy to use as os.system
, and even easier if you are building the argument list dynamically.
You need to set the current working directory of the process. If the .pdf files are located at /some/path/to/pdf/files/
:
>>> os.getcwd()
'/home/vz0'
>>> os.chdir('/some/path/to/pdf/files/')