summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/mixlib/shellout.rb6
-rw-r--r--lib/mixlib/shellout/unix.rb1
-rw-r--r--lib/mixlib/shellout/windows.rb4
-rw-r--r--spec/mixlib/shellout_spec.rb9
4 files changed, 14 insertions, 6 deletions
diff --git a/lib/mixlib/shellout.rb b/lib/mixlib/shellout.rb
index e4e0435..e446448 100644
--- a/lib/mixlib/shellout.rb
+++ b/lib/mixlib/shellout.rb
@@ -53,9 +53,9 @@ module Mixlib
# to determine if the command was successful. Normally set via options to new
attr_accessor :valid_exit_codes
- # When live_stream is set, stdout of the subprocess will be copied to it as
- # the subprocess is running. For example, if live_stream is set to STDOUT,
- # the command's output will be echoed to STDOUT.
+ # When live_stream is set, stdout and stderr of the subprocess will be
+ # copied to it as the subprocess is running. For example, if live_stream is
+ # set to STDOUT, the command's output will be echoed to STDOUT.
attr_accessor :live_stream
# ShellOut will push data from :input down the stdin of the subprocss.
diff --git a/lib/mixlib/shellout/unix.rb b/lib/mixlib/shellout/unix.rb
index 03f619b..aac28f0 100644
--- a/lib/mixlib/shellout/unix.rb
+++ b/lib/mixlib/shellout/unix.rb
@@ -288,6 +288,7 @@ module Mixlib
def read_stderr_to_buffer
while chunk = child_stderr.read_nonblock(READ_SIZE)
@stderr << chunk
+ @live_stream << chunk if @live_stream
end
rescue Errno::EAGAIN
rescue EOFError
diff --git a/lib/mixlib/shellout/windows.rb b/lib/mixlib/shellout/windows.rb
index c10c54f..832584a 100644
--- a/lib/mixlib/shellout/windows.rb
+++ b/lib/mixlib/shellout/windows.rb
@@ -165,7 +165,9 @@ module Mixlib
if ready.first.include?(stderr_read)
begin
- @stderr << stderr_read.readpartial(READ_SIZE)
+ next_chunk = stderr_read.readpartial(READ_SIZE)
+ @stderr << next_chunk
+ @live_stream << next_chunk if @live_stream
rescue EOFError
stderr_read.close
open_streams.delete(stderr_read)
diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb
index ac5b19d..277393b 100644
--- a/spec/mixlib/shellout_spec.rb
+++ b/spec/mixlib/shellout_spec.rb
@@ -449,12 +449,17 @@ describe Mixlib::ShellOut do
context "with a live stream" do
let(:stream) { StringIO.new }
- let(:ruby_code) { 'puts "hello"' }
+ let(:ruby_code) { '$stdout.puts "hello"; $stderr.puts "world"' }
let(:options) { { :live_stream => stream } }
it "should copy the child's stdout to the live stream" do
shell_cmd.run_command
- stream.string.should eql("hello#{LINE_ENDING}")
+ stream.string.should include("hello#{LINE_ENDING}")
+ end
+
+ it "should copy the child's stderr to the live stream" do
+ shell_cmd.run_command
+ stream.string.should include("world#{LINE_ENDING}")
end
end