繁体   English   中英

在Windows中从python子进程运行rsync

[英]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.

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