lib/frontkick/command.rb in frontkick-0.0.3 vs lib/frontkick/command.rb in frontkick-0.1.0
- old
+ new
@@ -10,10 +10,11 @@
cmd_array = cmd.kind_of?(Array) ? cmd : [cmd]
begin
timeout(opts[:timeout]) do # nil is for no timeout
duration = Benchmark.realtime do
stdin, out, err, wait_thr = Open3.popen3(*cmd_array)
+ stdin.close
pid = wait_thr.pid
stdout = out.read
stderr = err.read
exit_code = wait_thr.value.exitstatus
process_wait(pid)
@@ -25,13 +26,13 @@
process_wait(pid)
duration = opts[:timeout]
stdout = ""
stderr = "pid:#{pid}\tcommand:#{cmd_array.join(' ')} is timeout!"
ensure
- stdin.close unless stdin.nil?
- out.close unless out.nil?
- err.close unless err.nil?
- wait_thr.kill unless wait_thr.stop?
+ stdin.close if stdin and !stdin.closed?
+ out.close if out and !out.closed?
+ err.close if err and !err.closed?
+ wait_thr.kill if wait_thr and !wait_thr.stop?
end
CommandResult.new(stdout, stderr, exit_code, duration)
end