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

时间:2014-08-23 17:06:46

标签: c++ qt rsync qprocess

我正在尝试从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 *'排除受到尊重!有人可以解释为什么他们表现不同吗?

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

1 个答案:

答案 0 :(得分:1)

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

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

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