lib/backticks/command.rb in backticks-0.4.0 vs lib/backticks/command.rb in backticks-0.5.0
- old
+ new
@@ -19,12 +19,15 @@
# @return [Integer] child process ID
attr_reader :pid
# @return [String] all data captured (so far) from child's stdin/stdout/stderr
- attr_reader :captured_input, :captured_output, :captured_error, :status
+ attr_reader :captured_input, :captured_output, :captured_error
+ # @return [nil,Process::Status] result of command if it has ended; nil if still running
+ attr_reader :status
+
# Watch a running command.
def initialize(pid, stdin, stdout, stderr)
@pid = pid
@stdin = stdin
@stdout = stdout
@@ -91,15 +94,15 @@
ready, _, _ = IO.select(streams, [], [], 1)
# proxy STDIN to child's stdin
if ready && ready.include?(STDIN)
input = STDIN.readpartial(CHUNK) rescue nil
- @captured_input << input
if input
+ @captured_input << input
@stdin.write(input)
else
# our own STDIN got closed; proxy this fact to the child
- @stdin.close
+ @stdin.close unless @stdin.closed?
end
end
# capture child's stdout and maybe proxy to STDOUT
if ready && ready.include?(@stdout)