[英]Running rsync from python subprocess in windows
我需要在Windows 7 x64中使用Python 2.7應用程序運行rsync(使用cwRsync 5.5.0)。
在命令行中一切正常:將env中的CWRSYNCHOME設置為cwrsync二進制文件並運行以下命令
rsync.exe "/cygdrive/e/test" test1@192.168.1.14:
但是,當嘗試運行與python子進程相同的命令時:
process = subprocess.Popen(['rsync.exe', '/cygdrive/e/test', 'test1@192.168.1.14:'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
env={'CWRSYNCHOME': './bin'})
stdout, stderr = process.communicate()
print 'STDOUT:{}\nSTDERR:{}'.format(stdout, stderr)
我在stderr中收到以下錯誤:
rsync: pipe: Operation not permitted (1)
rsync error: error in IPC code (code 14) at pipe.c(59) [sender=3.1.2]
這是詳細的rsync stdout:
FILE_STRUCT_LEN=16, EXTRA_LEN=4
cmd=<NULL> machine=192.168.1.14 user=test1 path=.
cmd[0]=ssh cmd[1]=-l cmd[2]=test1 cmd[3]=192.168.1.14 cmd[4]=rsync cmd[5]=--server cmd[6]=-vvvvve.LsfxC cmd[7]=. cmd[8]=.
opening connection using: ssh -l test1 192.168.1.14 rsync --server -vvvvve.LsfxC . . (9 args)
[sender] _exit_cleanup(code=14, file=pipe.c, line=59): entered
[sender] _exit_cleanup(code=14, file=pipe.c, line=59): about to call exit(14)
嘗試設置shell = False並將命令作為單行傳遞(而不是cmd和args)-錯誤stil重復。
我究竟做錯了什么 ?
為了使其工作,rsync需要在cygwin的shell下運行:
process = subprocess.Popen(['sh.exe', '-c',
'rsync /cygdrive/e/test test1@192.168.1.14:'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
env={'CWRSYNCHOME': '/bin/',
'PATH': '/bin/'})
它正在工作(上面的示例中沒有ssh權限)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.