Need help with mixlib-shellout?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

127 Stars 69 Forks Apache License 2.0 598 Commits 7 Opened issues


mixin library for subprocess management, output collection

Services available


Need anything else?

Contributors list


Build Status Gem Version

Umbrella Project: Chef Foundation

Project State: Active

Issues Response Time Maximum: 14 days

Pull Request Response Time Maximum: 14 days

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


Simple Shellout

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

  require 'mixlib/shellout'
  find ="find . -name '*.rb'")

If all went well, the results are on

  puts find.stdout

prints diagnostic info to STDERR:
  puts "error messages" + find.stderr

Raise an exception if it didn't exit with 0


Advanced Shellout

In addition to the command to run there are other options that can be set to change the shellout behavior. The complete list of options can be found here:

Run a command as the

user with no extra ENV settings from
with a 1s timeout
  cmd ="apachectl", "start", :user => 'www', :environment => nil, :cwd => '/tmp', :timeout => 1)
  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 ="crontab -l -u #{@new_resource.user}", :input => crontab_lines.join("\n"))

Windows Impersonation Example

Invoke "whoami.exe" to demonstrate running a command as another user:

  whoami ="whoami.exe", :user => "username", :domain => "DOMAIN", :password => "password")

Invoke "whoami.exe" with elevated privileges:

  whoami ="whoami.exe", :user => "username", :domain => "DOMAIN", :password => "password", :elevated => true)

NOTE: The user 'admin' must have the 'Log on as a batch job' permission and the user chef is running as must have the 'Replace a process level token' and 'Adjust Memory Quotas for a process' permissions.

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.

See Also


For information on contributing to this project see


  • Copyright:: Copyright (c) 2011-2016 Chef Software, Inc.
  • License:: Apache License, Version 2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.