Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4650

Prepend output while streaming like foreman

$
0
0

I have this ruby script that I use quite often:

$stdin.each_line do |it|  it.strip!  eval(ARGV.first)end

For instance:

> dir | each "Dir.chdir(it) { puts it; system('bundle') }"codeBundle complete! 41 Gemfile dependencies, 165 gems now installed.Use `bundle info [gemname]` to see where a bundled gem is installed.code-rubyBundle complete! 6 Gemfile dependencies, 44 gems now installed.Use `bundle info [gemname]` to see where a bundled gem is installed.

I do this "puts it" quite often and would rather have my output be prepended by the "it".

e.g.

> dir | each "Dir.chdir(it) { system('bundle') }"[code] Bundle complete! 41 Gemfile dependencies, 165 gems now installed.[code] Use `bundle info [gemname]` to see where a bundled gem is installed.[code-ruby] Bundle complete! 6 Gemfile dependencies, 44 gems now installed.[code-ruby] Use `bundle info [gemname]` to see where a bundled gem is installed.

This is even more obvious with the parallel version:

Parallel.each($stdin.each_line.to_a) do |it|  it.strip!  eval(ARGV.first)end

Viewing all articles
Browse latest Browse all 4650

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>