Skip to content

Instantly share code, notes, and snippets.

@jpadams
Last active December 28, 2015 04:19
Show Gist options
  • Save jpadams/7441922 to your computer and use it in GitHub Desktop.
Save jpadams/7441922 to your computer and use it in GitHub Desktop.
Getting closer with windows commmand run
module MCollective
module Agent
class Windowsrun<RPC::Agent
action "run" do
command = "dir"
reply[:status] = run(command, :stdout => :out, :stderr => :err, :chomp => true)
end
def run(command, options)
if MCollective::Util.windows?
require 'win32/process'
# If creating the process doesn't outright fail, assume everything
# was okay. The caller wants to know our exit code, so we'll just use
# 0 or 1.
begin
Process.create(:command_line => command, :creation_flags => Process::CREATE_NO_WINDOW)
0
rescue Process::Error => e
1
end
else
super
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment