简体   繁体   中英

Rsync from python can't find path

I've tried to run rsync from python via Popen and via subprocess.check_call, getting the very same error:

subprocess.check_call(['rsync', '-au', '/opt/catflow/EpressCatalog/*', '/Users/pistacchio/dev/epress/catflow/portal/branches/noscript/frontend/static/repo/usr/2/catalogs/2/builds/ipad'])
rsync: link_stat "/opt/catflow/EpressCatalog/*" failed: No such file or directory (2)
rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-42/rsync/main.c(992) [sender=2.6.9]
*** CalledProcessError: Command '['rsync', '-au', '/opt/catflow/EpressCatalog/*', '/Users/pistacchio/dev/epress/catflow/portal/branches/noscript/frontend/static/repo/usr/2/catalogs/2/builds/ipad']' returned non-zero exit status 23

Seems like the problem is that it can't find (or access) /opt/catflow/EpressCatalog/* . Not only it exists, but running it from the command line gives a correct result.

Any help?

The subprocess module handle the quoting of arguments by itself. When there are whitespaces in one argument entry than it is quoted by default.

Simplified example :

['-input', 'eggs.txt', '-output', 'spam spam.txt']

Is called on the shell as

-input eggs.txt -output "spam spam.txt"

Security note : Do never use shell=True . It opens the risk for shell injection attacks. See the official docu for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM