https://github.com/dtinth/thru
Pipe a string through a shell command.
https://github.com/dtinth/thru
ruby
Last synced: over 1 year ago
JSON representation
Pipe a string through a shell command.
- Host: GitHub
- URL: https://github.com/dtinth/thru
- Owner: dtinth
- License: mit
- Created: 2014-08-07T06:59:03.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-08-07T06:59:47.000Z (almost 12 years ago)
- Last Synced: 2025-01-23T19:48:07.841Z (over 1 year ago)
- Topics: ruby
- Language: Ruby
- Homepage:
- Size: 121 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Thru
Pipes a string through a shell command's STDIN and returns STDOUT.
## Installation
gem install thru
## Usage
### Basic Usage
require 'thru'
text = "Hello world!"
text.thru('uuencode -')
# => "begin 644 -\n,2&5L;&\\@=V]R;&0A\n`\nend\n"
text | 'uuencode -'
# => "begin 644 -\n,2&5L;&\\@=V]R;&0A\n`\nend\n"
### Real-world Usage. Let's Convert Markdown to LaTeX!
Using [Pandoc](http://johnmacfarlane.net/pandoc/).
markdown = File.read('README.md')
latex = markdown | 'pandoc -f markdown -t latex'
## API
### String#thru(*command) → str
str | command → str
Passes the string through a shell command's STDIN. Captures and returns its STDOUT.
Raises a `RuntimeError` if the command returned non-zero exit code.
'wow' | 'gcc'
# (STDERR) gcc: fatal error: no input files
# (STDERR) compilation terminated.
# RuntimeError: pid 93761 exit 1
To suppress the error, true!
'wow' | 'gcc; true'
# (STDERR) gcc: fatal error: no input files
# (STDERR) compilation terminated.
# => ""
## Contributing
1. Fork it ( https://github.com/dtinth/thru/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request