Giter VIP home page Giter VIP logo

command-runner's Introduction

Command Runner

Build Status Code Climate Gem Version

Runs commands.

require 'command/runner'

line = Command::Runner.new("echo", "hello")
message = line.pass # => #<Command::Runner::Message:...>
message.exit_code   # => 0
message.stdout      # => "hello\n"
message.time        # => 0.00091773
message.process_id  # => 9622
message.line        # => "echo hello"

with interpolations...

line = Command::Runner.new("echo", "{interpolation}")
message = line.pass(:interpolation => "watermelons")
message.stdout # => "watermelons\n"
message.line   # => "echo watermelons"

that escapes bad stuff...

message = line.pass(:interpolation => "`uname -a`")
message.stdout # => "`uname -a`\n"
message.line   # => "echo \\`uname\\ -a\\`"

unless you don't want it to.

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...

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...

line = Command::Runner.new("some-non-existant-command", "")

line.pass.no_command? # => true

it'll tell you.

It calls the given block...

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

command-runner's People

Contributors

bitdeli-chef avatar teliosdev avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

command-runner's Issues

Bypass Shell

Process.spawn can take multiple arguments after the command name - this provides a safer alternative than to blanket escape the entire command. I suggest changing the Command::Runner::Spawn backend in order to cope with this ideal.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.