{"id":17134040,"url":"https://github.com/skorks/subshell_command","last_synced_at":"2025-04-13T08:53:51.134Z","repository":{"id":56896807,"uuid":"86980062","full_name":"skorks/subshell_command","owner":"skorks","description":"Simpler way to execute shell commands from within ruby processes","archived":false,"fork":false,"pushed_at":"2017-04-02T11:17:24.000Z","size":8,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-26T22:42:26.235Z","etag":null,"topics":["ruby","ruby-cli"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skorks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-02T10:50:04.000Z","updated_at":"2017-09-22T16:45:11.000Z","dependencies_parsed_at":"2022-08-21T01:20:40.135Z","dependency_job_id":null,"html_url":"https://github.com/skorks/subshell_command","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skorks%2Fsubshell_command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skorks%2Fsubshell_command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skorks%2Fsubshell_command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skorks%2Fsubshell_command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skorks","download_url":"https://codeload.github.com/skorks/subshell_command/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248688543,"owners_count":21145763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby","ruby-cli"],"created_at":"2024-10-14T19:43:44.105Z","updated_at":"2025-04-13T08:53:51.113Z","avatar_url":"https://github.com/skorks.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SubshellCommand\n\nIf, like me, you always forget when and how (and why) to use backticks or popen or whatever when trying to execute a shell command from within a ruby process, this should hopefully make life a little bit easier.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'subshell_command'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install subshell_command\n\n## Usage\n\nSimplest form:\n\n```ruby\nresult = SubshellCommand.execute(\"ls -al\")\nif result.success?\n  puts result.stdout_value\nelse\n  puts result.stderr_value\nend\n```\n\nBut we can do a little better with a block:\n\n```ruby\nSubshellCommand.execute(\"ls -al\") do |o|\n  o.cmd = \"pwd\"                       # we can override the command\n  o.redirect_stderr_to_stdout = true  # we can pipe stderr to stdout\n  o.current_directory = \"/\"           # we can override the working directory\n  o.env = {                           # we can provide some extra env vars\n    FOO: \"bar\"\n  }    \n  o.on_success = -\u003e(r) do             # we can provide a success callback\n    puts r.stdout_value\n  end\n  o.on_failure = -\u003e(r) do             # we can provide a failure callback\n    puts r.stderr_value\n  end\nend\n```\n\nAll of the above options have sensible defaults, so you can get away with:\n\n```ruby\nSubshellCommand.execute(\"ls -al\") do |o|\n  o.on_success = -\u003e(result) do             \n    puts result.stdout_value\n  end\nend\n```\n\nIf all you care about is doing something when the command succeeds.\n\nAlso all the code for this is in one file, which is on purpose, so if you'd rather not add an extra gem, just grab the file, dump it into your project and off you go.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/skorks/subshell_command.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskorks%2Fsubshell_command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskorks%2Fsubshell_command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskorks%2Fsubshell_command/lists"}