gpt4 book ai didi

c++ - 与 bash 命令行相比,rsync 与 QProcess 的运行方式不同

转载 作者:太空宇宙 更新时间:2023-11-04 11:29:14 26 4
gpt4 key购买 nike

我正在尝试从 QProcess 启动 rsync,虽然它运行,但与从命令行运行完全相同的命令相比,从 QProcess 运行时它的行为有所不同。

这是从 QProcess 运行时的命令和标准输出

/usr/bin/rsync -atv --stats --progress --port=873 --compress-level=9 --recursive --delete --exclude="/etc/*.conf" --exclude="A*" rsync://myhost.com/haast/tmp/mysync/* /tmp/mysync/

receiving incremental file list
created directory /tmp/mysync
A
0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=6/7)
B
0 100% 0.00kB/s 0:00:00 (xfer#2, to-check=5/7)
test.conf
0 100% 0.00kB/s 0:00:00 (xfer#3, to-check=4/7)
subdir/
subdir/A2
0 100% 0.00kB/s 0:00:00 (xfer#4, to-check=2/7)
subdir/C
0 100% 0.00kB/s 0:00:00 (xfer#5, to-check=1/7)
subdir/D
0 100% 0.00kB/s 0:00:00 (xfer#6, to-check=0/7)

Number of files: 7
Number of files transferred: 6
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 105
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 174
Total bytes received: 367

sent 174 bytes received 367 bytes 360.67 bytes/sec
total size is 0 speedup is 0.00

请注意,虽然我排除了“A*”,但它仍然复制了它们!现在从命令行运行完全相同的命令:

/usr/bin/rsync -atv --stats --progress --port=873 --compress-level=9 --recursive --delete --exclude="/etc/*.conf" --exclude="A*" rsync://myhost.com/haast/tmp/mysync/* /tmp/mysync/
receiving incremental file list
created directory /tmp/mysync
B
0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=4/5)
test.conf
0 100% 0.00kB/s 0:00:00 (xfer#2, to-check=3/5)
subdir/
subdir/C
0 100% 0.00kB/s 0:00:00 (xfer#3, to-check=1/5)
subdir/D
0 100% 0.00kB/s 0:00:00 (xfer#4, to-check=0/5)

Number of files: 5
Number of files transferred: 4
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 83
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 132
Total bytes received: 273

sent 132 bytes received 273 bytes 270.00 bytes/sec
total size is 0 speedup is 0.00

请注意,现在 'A*' 排除被尊重!有人可以解释为什么他们的表现不同吗?

A 注意到,如果我删除了排除项周围的引号,那么 QProcess 运行将正确执行。

最佳答案

在您的命令行执行中,bash 解释器执行先前的替换并删除引号,因此它们不会传递给 rsync arg 列表。

下一个脚本显示了如何执行 bash 替换:

[tmp]$ cat printargs.sh 
#!/bin/bash
echo $*
[tmp]$ ./printargs.sh --exclude="A*"
--exclude=A*

关于c++ - 与 bash 命令行相比,rsync 与 QProcess 的运行方式不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25464368/

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