L
L
larrabee2014-03-28 00:41:33
linux
larrabee, 2014-03-28 00:41:33

Python, rsync and subprocess.call - what's the problem?

Hello.
There is a python script, at some point rsync is called with parameters via subprocess.call. Simplified script. The function first generates an exclude_list string and returns it, rsync should accept it as a startup parameter.

print(exclude_list())
>> --exclude=var --exclude=opt --exclude=home
subprocess.call(['rsync', '-aAX', '/', '/mnt/', exclude_list()])

The problem is that if exclude_list is equal to a string like this:
print(exclude_list())
>> --exclude=var

then everything works fine, rsync skips this directory.
But as soon as the second exclude is added (1 code example), everything immediately breaks down, rsync starts without errors, but does not skip directories. Watched ps'om, all parameters are transferred to rsync'u.
Please explain how and why this happens. Thank you.
Python 3.4.0
Rsync 3.1.0
os Arch linux

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Popov, 2014-03-28
@larrabee

subprocess.call expects a list of arguments, one argument per list element.
If your exlude_list is a string, then it must be divided into parts and added to the list of arguments before passing it to subprocess.call, something like this:

subprocess.call(['rsync', '-aAX', '/', '/mnt/'] + exclude_list().split())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question