Passing Variables to Subprocess.Popen to run copy command

357 views Asked by At

I have a script which runs copy command to copy files and directories. Since, i have arguments stored in variables.

copy_cmd = ['Lang=en_US' , '/bin/cp' , '-r' , '-v']

Option['source']

Option['destination']

I'm passing the value of Option['source'] & Option['destination'] at run time. I'am unable to perform the command and getting....

child exception
AttributeError: list object has no attribute rfind

The command which i'am using is

copy_pid = subprocess.Popen([copy_cmd , Option['source'] , '/.' , 'Option['destination']'] , stdin = subprocess.PIPE , stdout = subprocess.PIPE)
1

There are 1 answers

4
miszcz2137 On

You need to pass lis of strings yet copy_cmd is already a list. So you meed to concatenate it and not insert as an element.

copy_pid = subprocess.Popen(copy_cmd + [Option['source'] , '/.' , Option['destination']] , stdin = subprocess.PIPE , stdout = subprocess.PIPE)

Also I don't understand what are those Option for so I just left them as they were.