GithubHelp home page GithubHelp logo

kanerogers / mixlib-shellout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chef/mixlib-shellout

0.0 2.0 0.0 354 KB

mixin library for subprocess management, output collection

License: Apache License 2.0

mixlib-shellout's Introduction

Mixlib::ShellOut

Provides a simplified interface to shelling out yet still collecting both standard out and standard error and providing full control over environment, working directory, uid, gid, etc.

No means for passing input to the subprocess is provided.

Example

Invoke find(1) to search for .rb files:

  find = Mixlib::ShellOut.new("find . -name '*.rb'")
  find.run_command

If all went well, the results are on stdout

  puts find.stdout

find(1) prints diagnostic info to STDERR:

  puts "error messages" + find.stderr

Raise an exception if it didn't exit with 0

  find.error!

Run a command as the www user with no extra ENV settings from /tmp

  cmd = Mixlib::ShellOut.new("apachectl", "start", :user => 'www', :env => nil, :cwd => '/tmp')
  cmd.run_command # etc.

STDIN Example

Invoke crontab to edit user cron:

  # :input only supports simple strings
  crontab_lines = [ "* * * * * /bin/true", "* * * * * touch /tmp/here" ]
  crontab = Mixlib::ShellOut.new("crontab -l -u #{@new_resource.user}", :input => crontab_lines.join("\n"))
  crontab.run_command

Windows Impersonation Example

Invoke crontab to edit user cron:

  whomai = Mixlib::ShellOut.new("whoami.exe", :user => "username", :domain => "DOMAIN", :password => "password")
  whoami.run_command      

Platform Support

Mixlib::ShellOut does a standard fork/exec on Unix, and uses the Win32 API on Windows. There is not currently support for JRuby.

License

Apache 2 Licensed. See LICENSE for full details.

See Also

mixlib-shellout's People

Contributors

hosh avatar danielsdeleo avatar schisamo avatar lamont-granquist avatar btm avatar akshaykarle avatar thcipriani avatar carmstrong avatar mdkent avatar coderanger avatar stevenproctor avatar

Watchers

James Cloos avatar Kane Rogers-Wong avatar

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.