Module: Veewee::Provider::Core::Helper::Shell
Instance Method Summary collapse
-
#shell_exec(command, options = {}) ⇒ Object
blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/185404 This should work on windows too now This will result in a ShellResult structure with stdout, stderr and status.
Instance Method Details
#shell_exec(command, options = {}) ⇒ Object
blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/185404 This should work on windows too now This will result in a ShellResult structure with stdout, stderr and status
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/veewee/provider/core/helper/shell.rb', line 23 def shell_exec(command, = {}) defaults = { :mute => true, :status => 0, :stderr => "&1" } = defaults.merge() result = ShellResult.new("","",-1) ui.info "Executing #{command}" unless [:mute] env.logger.debug "Command: \"#{command}\"" env.logger.debug "Output:" env.logger.debug "-------" escaped_command = command stderr_redirect = [:stderr]? [:stderr] : "&1" = {} [:external_encoding] = [:external_encoding] if [:external_encoding] IO.popen("#{escaped_command}"+ " 2>#{stderr_redirect}", ) do |pipe| pipe.each_line do |line| result.stdout += line ui.info(line, :new_line => false) unless [:mute] env.logger.debug(line.chomp) end result.status = Process.waitpid2(pipe.pid)[1].exitstatus if result.status.to_i != [:status] then ui.error "Error: We executed a shell command and the exit status was not #{[:status]}" ui.error "- Command :#{command}." ui.error "- Exitcode :#{result.status}." ui.error "- Output :\n#{result.stdout}" raise Veewee::Error,"Wrong exit code for command #{command}" end end return result end |