summaryrefslogtreecommitdiff
path: root/lib/mixlib/shellout.rb
diff options
context:
space:
mode:
authorMax Lincoln <max@devopsy.com>2014-07-09 16:05:17 -0400
committerMax Lincoln <max@devopsy.com>2014-07-17 13:01:04 -0400
commit5ce6ead83be1a46241db53e401f44c9a40f598ce (patch)
treede80864f2c23906496195ed55ad98e420d4ae558 /lib/mixlib/shellout.rb
parentb5e27147f0a5f0ccf44ff4968be2bdfb0c2ce35d (diff)
downloadmixlib-shellout-5ce6ead83be1a46241db53e401f44c9a40f598ce.tar.gz
Support separate live stream for stderr
Diffstat (limited to 'lib/mixlib/shellout.rb')
-rw-r--r--lib/mixlib/shellout.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/mixlib/shellout.rb b/lib/mixlib/shellout.rb
index e446448..a633819 100644
--- a/lib/mixlib/shellout.rb
+++ b/lib/mixlib/shellout.rb
@@ -54,10 +54,13 @@ module Mixlib
attr_accessor :valid_exit_codes
# 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.
+ # copied to it as the subprocess is running. The stderr will also be copied,
+ # unless live_stderr_stream is set to nil or a different object. For example,
+ # if live_stream is set to STDOUT, the command's output will be echoed to STDOUT.
attr_accessor :live_stream
+ attr_writer :live_stderr_stream
+
# ShellOut will push data from :input down the stdin of the subprocss.
# Normally set via options passed to new.
# Default: nil
@@ -163,6 +166,20 @@ module Mixlib
@command = command_args.size == 1 ? command_args.first : command_args
end
+ # When live_stderr_stream is set, the stderr of the subprocess will be
+ # copied to it as the subprocess is running. For example, if live_stderr_stream is
+ # set to STDERR, the command's output will be echoed to STDERR. The default
+ # value is to match live_stream, so setting live_stream to STDOUT will also
+ # set live_stderr_stream to STDOUT. If you only want the stdout of the subprocess
+ # copied, then you should explicitly set live_stderr_stream to nil.
+ def live_stderr_stream
+ # We can't use ||= because it would override an explicit nil
+ unless defined?(@live_stderr_stream)
+ @live_stderr_stream = live_stream
+ end
+ @live_stderr_stream
+ end
+
# Set the umask that the subprocess will have. If given as a string, it
# will be converted to an integer by String#oct.
def umask=(new_umask)
@@ -287,6 +304,9 @@ module Mixlib
self.valid_exit_codes = Array(setting)
when 'live_stream'
self.live_stream = setting
+ when 'live_stderr_stream'
+ puts "Setting to #{setting}"
+ self.live_stderr_stream = setting
when 'input'
self.input = setting
when 'logger'