Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/teliosdev/command-runner
Run commands.
https://github.com/teliosdev/command-runner
Last synced: 1 day ago
JSON representation
Run commands.
- Host: GitHub
- URL: https://github.com/teliosdev/command-runner
- Owner: teliosdev
- License: mit
- Created: 2013-06-20T10:20:08.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-02-21T05:52:23.000Z (over 9 years ago)
- Last Synced: 2024-10-31T13:07:39.106Z (15 days ago)
- Language: Ruby
- Homepage: http://rdoc.info/github/redjazz96/command-runner
- Size: 349 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Command Runner
[![Build Status](https://travis-ci.org/medcat/command-runner.png?branch=master)](https://travis-ci.org/medcat/command-runner) [![Code Climate](https://codeclimate.com/github/medcat/command-runner.png)](https://codeclimate.com/github/medcat/command-runner) [![Gem Version](https://badge.fury.io/rb/command-runner.svg)](http://badge.fury.io/rb/command-runner)Runs commands.
```Ruby
require 'command/runner'line = Command::Runner.new("echo", "hello")
message = line.pass # => #
message.exit_code # => 0
message.stdout # => "hello\n"
message.time # => 0.00091773
message.process_id # => 9622
message.line # => "echo hello"
```with interpolations...
```Ruby
line = Command::Runner.new("echo", "{interpolation}")
message = line.pass(:interpolation => "watermelons")
message.stdout # => "watermelons\n"
message.line # => "echo watermelons"
```that escapes bad stuff...
```Ruby
message = line.pass(:interpolation => "`uname -a`")
message.stdout # => "`uname -a`\n"
message.line # => "echo \\`uname\\ -a\\`"
```unless you don't want it to.
```Ruby
line = Command::Runner.new("echo", "{{interpolation}}")
line.force_unsafe!
message = line.pass(:interpolation => "`uname -a`")
message.stdout # => "Linux Hyperion 3.8.0-25-generic #37-Ubuntu SMP Thu Jun 6 20:47:07 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux\n"
message.line # => "echo `uname -a`"
```It can also use different methods to run commands...
```Ruby
line = Command::Runner.new("echo", "something")
line.backend = Command::Runner::Backends::Spawn.new
line.pass
```but defaults to the best one.
If you run a command that doesn't exist on the machine...
```Ruby
line = Command::Runner.new("some-non-existant-command", "")line.pass.no_command? # => true
```it'll tell you.
It calls the given block...
```Ruby
line = Command::Runner.new("echo", "{something}")line.pass(something: "hello") do |message|
message.stdout
end # => "hello\n"
```and return the value.
## Compatibility
It works on- 2.1.0
- 2.0.0
- 1.9.3
- JRuby (2.0 Mode)
- JRuby (1.9 Mode)unless the travis build fails.
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/medcat/command-runner/trend.png)](https://bitdeli.com/free "Bitdeli Badge")