gpt4 book ai didi

python - 在 Windows 中从 python 子进程运行 rsync

转载 作者:太空宇宙 更新时间:2023-11-03 17:06:25 25 4
gpt4 key购买 nike

我需要在 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 标准输出:

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) - 错误仍然重复。

我做错了什么?

最佳答案

要使其工作,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 授权)。

关于python - 在 Windows 中从 python 子进程运行 rsync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34556811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com