Class: Train::Transports::Local::Connection::WindowsPipeRunner
- Inherits:
-
Object
- Object
- Train::Transports::Local::Connection::WindowsPipeRunner
- Defined in:
- lib/train/transports/local.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(powershell_cmd = "powershell") ⇒ WindowsPipeRunner
constructor
A new instance of WindowsPipeRunner.
-
#run_command(cmd, _opts) ⇒ Object
Local::CommandResult with stdout, stderr and exitstatus Note that exitstatus ($?) in PowerShell is boolean, but we use a numeric exit code.
Constructor Details
#initialize(powershell_cmd = "powershell") ⇒ WindowsPipeRunner
Returns a new instance of WindowsPipeRunner.
177 178 179 180 181 182 |
# File 'lib/train/transports/local.rb', line 177 def initialize(powershell_cmd = "powershell") @powershell_cmd = powershell_cmd @server_pid = nil @pipe = acquire_pipe raise PipeError if @pipe.nil? end |
Instance Method Details
#close ⇒ Object
215 216 217 218 |
# File 'lib/train/transports/local.rb', line 215 def close Process.kill("KILL", @server_pid) unless @server_pid.nil? @server_pid = nil end |
#run_command(cmd, _opts) ⇒ Object
Returns Local::CommandResult with stdout, stderr and exitstatus Note that exitstatus ($?) in PowerShell is boolean, but we use a numeric exit code. A command that succeeds without setting an exit code will have exitstatus 0 A command that exits with an exit code will have that value as exitstatus A command that fails (e.g. throws exception) before setting an exit code will have exitstatus 1.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/train/transports/local.rb', line 190 def run_command(cmd, _opts) script = "$ProgressPreference='SilentlyContinue';" + cmd encoded_script = Base64.strict_encode64(script) # TODO: no way to safely implement timeouts here. begin @pipe.puts(encoded_script) @pipe.flush rescue Errno::EPIPE # Retry once if the pipe went away begin # Maybe the pipe went away, but the server didn't? Reset it, to get a clean start. close rescue Errno::EIO # Ignore - server already went away end @pipe = acquire_pipe raise PipeError if @pipe.nil? @pipe.puts(encoded_script) @pipe.flush end res = OpenStruct.new(JSON.parse(Base64.decode64(@pipe.readline))) Local::CommandResult.new(res.stdout, res.stderr, res.exitstatus) end |