通过Cygwin在Python脚本中运行rsync命令
我正在尝试让这个工作,但我总是遇到这个问题:
subprocess.call(['c:/cygwin/bin/bash.exe', '--login', '-i', 'rsync', '-zrgo', '--omit-dir-times', '--verbose', '--delete', '.', 'usertwo@192.168.1.1:/var/www/project/'])
--
bash: /usr/bin/rsync: cannot execute binary file
126
1 个回答
1
你缺少了'-c'(命令)这个选项给bash。此外,你应该把rsync命令作为一个完整的字符串提供:
subprocess.call(['c:/cygwin/bin/bash.exe', '--login', '-i', '-c', 'rsync -zrgo --omit-dir-times --verbose --delete . usertwo@192.168.1.1:/var/www/project/'])
来自手册页面的说明:
-c string If the -c option is present, then commands are read from
string. If there are arguments after the string, they are
assigned to the positional parameters, starting with $0.
例如:
# bash /bin/ls
/bin/ls: /bin/ls: cannot execute binary file
# bash -c "/bin/ls -l"
<ls output>