gpt4 book ai didi

ruby - 如何从 ruby​​ 获取交互式程序的进度?

转载 作者:数据小太阳 更新时间:2023-10-29 07:33:05 25 4
gpt4 key购买 nike

我正在尝试创建一个 macruby 应用程序,它使用 --progress 参数调用 rsync 脚本,但是 rsync 显示其进度的方式是更改同一行,而不是在其输出中添加新行,所以我怎么能抢这个数据?

最佳答案

Rsync 允许您使用 --log-format 选项更改正在显示的信息的格式:

--log-format=FORMAT
This allows you to specify exactly what the rsync client outputs to the user on a per-file basis. The format is a text string containing embedded
single-character escape sequences prefixed with a percent (%) character. For a list of the possible escape characters, see the "log format" set-
ting in the rsyncd.conf manpage. (Note that this option does not affect what a daemon logs to its logfile.)

Specifying this option will mention each file, dir, etc. that gets updated in a significant way (a transferred file, a recreated symlink/device,
or a touched directory) unless the itemize-changes escape (%i) is included in the string, in which case the logging of names increases to mention
any item that is changed in any way (as long as the receiving side is at least 2.6.4). See the --itemize-changes option for a description of the
output of "%i".

The --verbose option implies a format of "%n%L", but you can use --log-format without --verbose if you like, or you can override the format of its
per-file output using this option.

Rsync will output the log-format string prior to a file's transfer unless one of the transfer-statistic escapes is requested, in which case the
logging is done at the end of the file's transfer. When this late logging is in effect and --progress is also specified, rsync will also output
the name of the file being transferred prior to its progress information (followed, of course, by the log-format output).

您应该能够即时将其配置为更有用的东西。

此外,如果您使用过 popen3,您应该能够捕获传输百分比,并使用它来创建您自己的进度条。

关于ruby - 如何从 ruby​​ 获取交互式程序的进度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4125740/

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