Class: SpecInfra::Backend::Cmd
- Includes:
- PowerShell::ScriptHelper
- Defined in:
- lib/specinfra/backend/cmd.rb
Instance Method Summary collapse
Methods included from PowerShell::ScriptHelper
#add_pre_command, #build_command, #check_running, #create_script, #encode_script
Methods inherited from Base
#check_zero, #commands, #method_missing, #set_commands, #set_example
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class SpecInfra::Backend::Base
Instance Method Details
#check_os ⇒ Object
33 34 35 36 |
# File 'lib/specinfra/backend/cmd.rb', line 33 def check_os # Dirty hack for specs 'Windows' end |
#execute_script(script) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/specinfra/backend/cmd.rb', line 20 def execute_script script if Open3.respond_to? :capture3 stdout, stderr, status = Open3.capture3(script) # powershell still exits with 0 even if there are syntax errors, although it spits the error out into stderr # so we have to resort to return an error exit code if there is anything in the standard error status = 1 if status == 0 and !stderr.empty? { :stdout => stdout, :stderr => stderr, :status => status } else stdout = `#{script} 2>&1` { :stdout => stdout, :stderr => nil, :status => $? } end end |
#run_command(cmd, opts = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/specinfra/backend/cmd.rb', line 8 def run_command(cmd, opts={}) script = create_script(cmd) result = execute_script %Q{#{powershell} -encodedCommand #{encode_script(script)}} if @example @example.[:command] = script @example.[:stdout] = result[:stdout] + result[:stderr] end CommandResult.new :stdout => result[:stdout], :stderr => result[:stderr], :exit_status => result[:status] end |