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
-
#initialize(powershell_cmd = "powershell") ⇒ WindowsShellRunner
constructor
A new instance of WindowsShellRunner.
- #run_command(script) ⇒ Object
Constructor Details
#initialize(powershell_cmd = "powershell") ⇒ WindowsShellRunner
Returns a new instance of WindowsShellRunner.
118 119 120 |
# File 'lib/train/transports/local.rb', line 118 def initialize(powershell_cmd = "powershell") @powershell_cmd = powershell_cmd end |
Instance Method Details
#run_command(script) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/train/transports/local.rb', line 122 def run_command(script) # 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.run_command Local::CommandResult.new(res.stdout, res.stderr, res.exitstatus) end |