diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | CONTRIBUTIONS.md | 1 | ||||
-rw-r--r-- | lib/mixlib/shellout.rb | 6 | ||||
-rw-r--r-- | lib/mixlib/shellout/unix.rb | 7 | ||||
-rw-r--r-- | lib/mixlib/shellout/windows.rb | 4 | ||||
-rw-r--r-- | spec/mixlib/shellout_spec.rb | 19 |
6 files changed, 24 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ed36836..f4c1b75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,5 +8,5 @@ * Remove GC.disable hack for non-ruby 1.8.8 * Handle ESRCH from getpgid of a zombie on OS X * Fix "TypeError: no implicit conversion from nil to integer" due to nil "token" passed to CloseHandle. MIXLIB-25. - +* $stderr of the command process is now reflected in the live_stream in addition to $stdout. (MIXLIB-19) ## Last Release: 1.3.0 (12/03/2013) diff --git a/CONTRIBUTIONS.md b/CONTRIBUTIONS.md index 6e37f30..9356c4e 100644 --- a/CONTRIBUTIONS.md +++ b/CONTRIBUTIONS.md @@ -7,3 +7,4 @@ Example Contribution: # mixlib-shellout Contributions: * **carmstrong**: Added error? method to see if the command was successful. +* **akshaykarle**: Added the functionality to reflect $stderr when using live_stream. 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..b8f4a17 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 @@ -345,12 +346,12 @@ module Mixlib def reap_errant_child return if attempt_reap - @terminate_reason = "Command execeded allowed execution time, process terminated" - logger.error("Command execeded allowed execution time, sending TERM") if logger + @terminate_reason = "Command exceeded allowed execution time, process terminated" + logger.error("Command exceeded allowed execution time, sending TERM") if logger Process.kill(:TERM, child_pgid) sleep 3 attempt_reap - logger.error("Command execeded allowed execution time, sending KILL") if logger + logger.error("Command exceeded allowed execution time, sending KILL") if logger Process.kill(:KILL, child_pgid) reap 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..5dcb6a7 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 @@ -922,8 +927,8 @@ describe Mixlib::ShellOut do shell_cmd.stdout.should include("nanana cant hear you") shell_cmd.status.termsig.should == 9 - log_output.string.should include("Command execeded allowed execution time, sending TERM") - log_output.string.should include("Command execeded allowed execution time, sending KILL") + log_output.string.should include("Command exceeded allowed execution time, sending TERM") + log_output.string.should include("Command exceeded allowed execution time, sending KILL") end end @@ -1025,7 +1030,7 @@ describe Mixlib::ShellOut do let(:ruby_code) { "STDIN.close; sleep 0.5; STDOUT.puts :win" } let(:options) { { :input => "Random data #{rand(100000)}" } } - it 'should not hang or lose outupt' do + it 'should not hang or lose output' do stdout.should eql("win#{LINE_ENDING}") end end @@ -1033,7 +1038,7 @@ describe Mixlib::ShellOut do context 'with subprocess that closes stdout and continues writing to stderr' do let(:ruby_code) { "STDOUT.close; sleep 0.5; STDERR.puts :win" } - it 'should not hang or lose outupt' do + it 'should not hang or lose output' do stderr.should eql("win#{LINE_ENDING}") end end @@ -1041,7 +1046,7 @@ describe Mixlib::ShellOut do context 'with subprocess that closes stderr and continues writing to stdout' do let(:ruby_code) { "STDERR.close; sleep 0.5; STDOUT.puts :win" } - it 'should not hang or lose outupt' do + it 'should not hang or lose output' do stdout.should eql("win#{LINE_ENDING}") end end |