communicators/ssh: Filter command stdout output
This commit is contained in:
parent
3c9e3c6f36
commit
155c78ea93
@ -19,8 +19,12 @@ module VagrantPlugins
|
|||||||
module CommunicatorSSH
|
module CommunicatorSSH
|
||||||
# This class provides communication with the VM via SSH.
|
# This class provides communication with the VM via SSH.
|
||||||
class Communicator < Vagrant.plugin("2", :communicator)
|
class Communicator < Vagrant.plugin("2", :communicator)
|
||||||
|
# Marker for start of PTY enabled command output
|
||||||
PTY_DELIM_START = "bccbb768c119429488cfd109aacea6b5-pty"
|
PTY_DELIM_START = "bccbb768c119429488cfd109aacea6b5-pty"
|
||||||
|
# Marker for end of PTY enabled command output
|
||||||
PTY_DELIM_END = "bccbb768c119429488cfd109aacea6b5-pty"
|
PTY_DELIM_END = "bccbb768c119429488cfd109aacea6b5-pty"
|
||||||
|
# Marker for start of regular command output
|
||||||
|
CMD_GARBAGE_MARKER = "41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh"
|
||||||
|
|
||||||
include Vagrant::Util::ANSIEscapeCodeRemover
|
include Vagrant::Util::ANSIEscapeCodeRemover
|
||||||
include Vagrant::Util::Retryable
|
include Vagrant::Util::Retryable
|
||||||
@ -490,16 +494,32 @@ module VagrantPlugins
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
marker_found = false
|
||||||
|
data_buffer = ''
|
||||||
|
|
||||||
ch.exec(shell_cmd(opts)) do |ch2, _|
|
ch.exec(shell_cmd(opts)) do |ch2, _|
|
||||||
# Setup the channel callbacks so we can get data and exit status
|
# Setup the channel callbacks so we can get data and exit status
|
||||||
ch2.on_data do |ch3, data|
|
ch2.on_data do |ch3, data|
|
||||||
# Filter out the clear screen command
|
# Filter out the clear screen command
|
||||||
data = remove_ansi_escape_codes(data)
|
data = remove_ansi_escape_codes(data)
|
||||||
@logger.debug("stdout: #{data}")
|
|
||||||
if pty
|
if pty
|
||||||
pty_stdout << data
|
pty_stdout << data
|
||||||
else
|
else
|
||||||
yield :stdout, data if block_given?
|
if !marker_found
|
||||||
|
data_buffer << data
|
||||||
|
marker_index = data_buffer.index(CMD_GARBAGE_MARKER)
|
||||||
|
if marker_index
|
||||||
|
marker_found = true
|
||||||
|
data_buffer.slice!(0, marker_index + CMD_GARBAGE_MARKER.size)
|
||||||
|
data.replace data_buffer
|
||||||
|
data_buffer = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if block_given? && marker_found
|
||||||
|
yield :stdout, data
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -516,7 +536,7 @@ module VagrantPlugins
|
|||||||
|
|
||||||
# Close the channel, since after the exit status we're
|
# Close the channel, since after the exit status we're
|
||||||
# probably done. This fixes up issues with hanging.
|
# probably done. This fixes up issues with hanging.
|
||||||
channel.close
|
ch.close
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the terminal
|
# Set the terminal
|
||||||
@ -563,7 +583,7 @@ module VagrantPlugins
|
|||||||
data = data.force_encoding('ASCII-8BIT')
|
data = data.force_encoding('ASCII-8BIT')
|
||||||
ch2.send_data data
|
ch2.send_data data
|
||||||
else
|
else
|
||||||
ch2.send_data "#{command}\n".force_encoding('ASCII-8BIT')
|
ch2.send_data "printf '#{CMD_GARBAGE_MARKER}'\n#{command}\n".force_encoding('ASCII-8BIT')
|
||||||
# Remember to exit or this channel will hang open
|
# Remember to exit or this channel will hang open
|
||||||
ch2.send_data "exit\n"
|
ch2.send_data "exit\n"
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user