Created
August 1, 2013 14:23
-
-
Save avdi/6131832 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Open3.pipeline_r( | |
| %W[xmllint --xinclude --xmlout #{spine_file}], | |
| # In order to clean up extraneous namespace declarations we need a second | |
| # xmllint process | |
| %W[xmllint --format --nsclean --xmlout -]) do |output, wait_thr| | |
| open(codex_file, 'w') do |f| | |
| IO.copy_stream(output, f) | |
| end | |
| end |
So it is basically piping the output from the first command into the input of the second command then passing the output of the last command to the block.
So command_one | command_two > OUTPUT
Right?
Author
Yep. And then IO.copy_stream pipes the output into a file. Yay!
Author
The important thing is that these are real pipes - it's not collecting all the output from the first before it starts executing the second process.
I use your capture_stream block in metric_fu, but I still am in copypasta land with pipes. https://github.com/metricfu/metric_fu/pull/108/files#L2R37 https://github.com/metricfu/metric_fu/blob/297c64/lib/metric_fu/logging/mf_debugger.rb#L26
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That is awesome, see http://www.ruby-doc.org/stdlib-2.0/libdoc/open3/rdoc/Open3.html#method-c-pipeline_r for more details.