Skip to content
mixin library for subprocess management, output collection
Ruby Other
Latest commit b892ec4 @mwrock mwrock Merge pull request #119 from chef/rel_2_2_6
release 2.2.6


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.


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

  find ="find . -name '*.rb'")

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


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

  cmd ="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 ="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")

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.


Apache 2 Licensed. See LICENSE for full details.

See Also

Something went wrong with that request. Please try again.