Как получить прогресс интерактивной программы от ruby?

Я пытаюсь создать приложение macruby, которое вызывает скрипт rsync с аргументом --progress, но способ, которым rsync отображает свой прогресс, заключается в изменении одной и той же строки, а не добавлении новых строк в свой вывод, так как я могу получить эти данные ?


person Marcel M.    schedule 08.11.2010    source источник
comment
Проблема в том, что rsync пишет в ту же строку, я нашел способ, основанный на этом coderrr.wordpress.com/2008/10/21/, который использует IO.popen readpartial для получения частичных данных.   -  person Marcel M.    schedule 15.12.2010


Ответы (2)


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, и использовать его для создания собственного индикатора выполнения.

person the Tin Man    schedule 16.11.2010

вы должны использовать IO.popen с блочной нотацией

person mpapis    schedule 16.11.2010