Class: Train::Transports::Local::Connection::WindowsShellRunner
- Inherits:
-
Object
- Object
- Train::Transports::Local::Connection::WindowsShellRunner
- Defined in:
- lib/train/transports/local.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(powershell_cmd = "powershell") ⇒ WindowsShellRunner
constructor
A new instance of WindowsShellRunner.
- #run_command(script, opts) ⇒ Object
Constructor Details
#initialize(powershell_cmd = "powershell") ⇒ WindowsShellRunner
Returns a new instance of WindowsShellRunner.
143 144 145 |
# File 'lib/train/transports/local.rb', line 143 def initialize(powershell_cmd = "powershell") @powershell_cmd = powershell_cmd end |
Instance Method Details
#close ⇒ Object
167 168 169 |
# File 'lib/train/transports/local.rb', line 167 def close # nothing to do at the moment end |
#run_command(script, opts) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/train/transports/local.rb', line 147 def run_command(script, opts) # Prevent progress stream from leaking into stderr script = "$ProgressPreference='SilentlyContinue';" + script # Encode script so PowerShell can use it script = script.encode("UTF-16LE", "UTF-8") base64_script = Base64.strict_encode64(script) cmd = "#{@powershell_cmd} -NoProfile -EncodedCommand #{base64_script}" res = Mixlib::ShellOut.new(cmd) res.timeout = opts[:timeout] begin res.run_command rescue Mixlib::ShellOut::CommandTimeout raise Train::CommandTimeoutReached end Local::CommandResult.new(res.stdout, res.stderr, res.exitstatus) end |