class EY::Serverside::Spawner::Child
Attributes
stderr_fd[R]
stdout_fd[R]
Public Class Methods
new(command, shell, server = nil)
click to toggle source
# File lib/engineyard-serverside/spawner.rb, line 102 def initialize(command, shell, server = nil) @command = command @shell = shell @server = server @output = "" end
Public Instance Methods
append_to_buffer(fd,data)
click to toggle source
# File lib/engineyard-serverside/spawner.rb, line 161 def append_to_buffer(fd,data) case fd when @stdout_fd @shell.command_out data @output << data when @stderr_fd @shell.command_err data @output << data end end
close(fd)
click to toggle source
# File lib/engineyard-serverside/spawner.rb, line 153 def close(fd) case fd when @stdout_fd then @stdout_fd = nil when @stderr_fd then @stderr_fd = nil end fd.close rescue true end
finished(status)
click to toggle source
# File lib/engineyard-serverside/spawner.rb, line 141 def finished(status) @status = status end
ios()
click to toggle source
# File lib/engineyard-serverside/spawner.rb, line 137 def ios [@stdout_fd, @stderr_fd].compact end
result()
click to toggle source
# File lib/engineyard-serverside/spawner.rb, line 145 def result if @status Result.new(@command, @status.success?, @output, @server) else raise "No result from unfinished child process" end end
spawn()
click to toggle source
# File lib/engineyard-serverside/spawner.rb, line 109 def spawn @shell.command_show @command #stdin, @stdout_fd, @stderr_fd, @waitthr = Open3.popen3(@cmd) #stdin.close stdin_rd, stdin_wr = IO.pipe @stdout_fd, stdout_wr = IO.pipe @stderr_fd, stderr_wr = IO.pipe @pid = fork do stdin_wr.close @stdout_fd.close @stderr_fd.close STDIN.reopen(stdin_rd) STDOUT.reopen(stdout_wr) STDERR.reopen(stderr_wr) Kernel.exec(@command) raise "Exec failed!" end stdin_rd.close stdin_wr.close stdout_wr.close stderr_wr.close [@pid, @stdout_fd, @stderr_fd] end