rsync
命令:
sshpass -p 'test' rsync -v -e 'ssh -p 2200' --stats --timeout=60 anonymous@localhost:/DSK1/SSN/LOG[0-9]_F/17191/l134191l.17.bnx L134201707101100f.amalthea
此命令适用于asyncio.subprocess.create_subprocess_shell
,但我想将其作为列表传递给create_subprocess_exec
asyncio.subprocess.create_subprocess_exec(*cmdList, stdin=..., ...)
我尝试过将cmdString.split()
拆分为
['sshpass', '-p', "'test'", 'rsync', '-v', '-e', "'ssh", '-p', "2200'", '--stats', '--timeout=60', 'anonymous@localhost:/DSK1/SSN/LOG[0-9]_F/17191/l134191l.17.bnx', 'L134201707101100f.amalthea']
但是rsync
正在引用报价。具体做法是:
Unexpected remote arg: anonymous@localhost:/DSK1/SSN/LOG[0-9]_F/17191/l134191i.17.bnx
rsync error: syntax or usage error (code 1) at main.c(1361) [sender=3.1.2]
答案 0 :(得分:2)
Shells使用空格作为输入字段分隔符。为了保护任何空格,使用引号,或转义空格。
运行asyncio.subprocess.create_subprocess_exec
时,字段已经分开,空格不视为输入字段分隔符。
ssh -p 2200
应放在一个字段中。 rsync
会按原样看到它。在shell中引用它来保护空白。
["sshpass", "-p", "test", "rsync", "-v", "-e", "ssh -p 2200", "--stats",
"--timeout=60", "anonymous@localhost:/DSK1/SSN/LOG[0-9]_F/17191/l134191l.17.bnx",
"L134201707101100f.amalthea"]