2

the string that contains a file looks like this in the console:

>>> target_file 'src//data//annual_filings//ABB Ltd//ABB_ar_2015.pdf' 

I got the target_file from a call to os.walk The goal is to build a command to run in subprocess.call Something like:

from subprocess import call cmd_ = r'qpdf-7.0.0/bin/qpdf --password=%s --decrypt %s %s' %('', target_file, target_file) call([cmd_]) 

I tried different variations, setting shell to either True or False. Replacing the // with /,\ etc. The issue seems to be with the space in the folder (I can not change the folder name).

The python code needs to run on Windows

1
  • Why does your path have a double forward slash? Commented Dec 14, 2017 at 10:21

1 Answer 1

3

you have to define cmd_ as a list of arguments not a list with a sole string in it, or subprocess interprets the string as the command (doesn't even try to split the args):

cmd_ = ['qpdf-7.0.0/bin/qpdf','--password=%s'%'','--decrypt',target_file, target_file] call(cmd_) 

and leave the quoting to subprocess

As a side note, no need to double the slashes. It works, but that's unnecessary.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.