lib/ztk/command.rb in ztk-0.2.3 vs lib/ztk/command.rb in ztk-0.2.4
- old
+ new
@@ -63,14 +63,14 @@
#
# cmd = ZTK::Command.new
# puts cmd.exec("hostname -f").inspect
def exec(command, options={})
- def log_header(tag, command)
+ def log_header(tag)
count = 8
sep = ("=" * count)
- header = [sep, "[ #{tag} ]", sep, "[ #{self.inspect} ]", sep, "[ #{command} ]", sep, "[ #{tag} ]", sep].join
+ header = [sep, "[ #{tag} ]", sep, "[ #{self.inspect} ]", sep, "[ #{tag} ]", sep].join
"#{header}\n"
end
options = OpenStruct.new({ :exit_code => 0, :silence => false }.merge(options))
log(:debug) { "options(#{options.inspect})" }
@@ -100,11 +100,13 @@
child_stderr_writer.close
reader_writer_key = {parent_stdout_reader => :stdout, parent_stderr_reader => :stderr}
reader_writer_map = {parent_stdout_reader => @config.stdout, parent_stderr_reader => @config.stderr}
- direct_log(:debug) { log_header("STARTED", command) }
+ direct_log(:debug) { log_header("COMMAND") }
+ direct_log(:debug) { "#{command}\n" }
+ direct_log(:debug) { log_header("STARTED") }
loop do
break if reader_writer_map.keys.all?{ |reader| reader.eof? }
sockets = IO.select(reader_writer_map.keys).first
sockets.each do |socket|
@@ -112,30 +114,30 @@
next if (data.nil? || data.empty?)
case reader_writer_key[socket]
when :stdout then
if !stdout_header
- direct_log(:debug) { log_header("STDOUT", command) }
+ direct_log(:debug) { log_header("STDOUT") }
stdout_header = true
stderr_header = false
end
reader_writer_map[socket].write(data) unless options.silence
direct_log(:debug) { data }
when :stderr then
if !stderr_header
- direct_log(:warn) { log_header("STDERR", command) }
+ direct_log(:warn) { log_header("STDERR") }
stderr_header = true
stdout_header = false
end
reader_writer_map[socket].write(data) unless options.silence
direct_log(:warn) { data }
end
output += data
end
end
- direct_log(:debug) { log_header("STOPPED", command) }
+ direct_log(:debug) { log_header("STOPPED") }
Process.waitpid(pid)
parent_stdout_reader.close
parent_stderr_reader.close