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

发布于 2024-10-01 16:36:26 字数 105 浏览 4 评论 0原文

我正在尝试创建一个使用 --progress 参数调用 rsync 脚本的 macruby 应用程序,但 rsync 显示其进度的方式是更改同一行,而不是在其输出中添加新行,那么我如何获取此数据?

I'm trying to create a macruby app that calls a rsync script with the --progress argument, but the way rsync displays its progress is by changing the same line, not adding new lines to its output, so how can I grab this data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神爱温柔 2024-10-08 16:36:26

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,您应该能够捕获传输数量的百分比,并使用它来创建您自己的进度条。

Rsync lets you change the format of the information being displayed using the --log-format option:

--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).

You should be able to configure it on the fly into something more usable.

Also, you should be able to capture the percent transferred number if you've used popen3, and use that to create your own progress bar.

荭秂 2024-10-08 16:36:26

您应该使用带有块符号的 IO.popen

you should use IO.popen with block notation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文