@@ -150,7 +150,7 @@ def run_command(self, command, sudo=False, user=None, stop_on_errors=True,
150150 raised otherwise
151151 :type host_args: tuple or list
152152 :param encoding: Encoding to use for output. Must be valid
153- `Python codec <https://docs.python.org/2.7/ library/codecs.html>`_
153+ `Python codec <https://docs.python.org/library/codecs.html>`_
154154 :type encoding: str
155155 :param timeout: (Optional) Timeout in seconds for reading from stdout
156156 or stderr. Defaults to no timeout. Reading from stdout/stderr will
@@ -218,14 +218,14 @@ def join(self, output, consume_output=False, timeout=None):
218218 continue
219219 client = self .host_clients [host ]
220220 channel = host_out .channel
221+ stdout , stderr = self .reset_output_generators (
222+ host_out , client = client , channel = channel , timeout = timeout )
221223 try :
222224 client .wait_finished (channel , timeout = timeout )
223225 except Timeout :
224226 raise Timeout (
225227 "Timeout of %s sec(s) reached on host %s with command "
226228 "still running" , timeout , host )
227- stdout = host_out .stdout
228- stderr = host_out .stderr
229229 if timeout :
230230 # Must consume buffers prior to EOF check
231231 self ._consume_output (stdout , stderr )
@@ -237,6 +237,36 @@ def join(self, output, consume_output=False, timeout=None):
237237 self ._consume_output (stdout , stderr )
238238 self .get_exit_codes (output )
239239
240+ def reset_output_generators (self , host_out , timeout = None ,
241+ client = None , channel = None ,
242+ encoding = 'utf-8' ):
243+ """Reset output generators for host output.
244+
245+ :param host_out: Host output
246+ :type host_out: :py:class:`pssh.output.HostOutput`
247+ :param client: (Optional) SSH client
248+ :type client: :py:class:`pssh.ssh2_client.SSHClient`
249+ :param channel: (Optional) SSH channel
250+ :type channel: :py:class:`ssh2.channel.Channel`
251+ :param timeout: (Optional) Timeout setting
252+ :type timeout: int
253+ :param encoding: (Optional) Encoding to use for output. Must be valid
254+ `Python codec <https://docs.python.org/library/codecs.html>`_
255+ :type encoding: str
256+
257+ :rtype: tuple(stdout, stderr)
258+ """
259+ channel = host_out .channel if channel is None else channel
260+ client = self .host_clients [host_out .host ] if client is None else client
261+ stdout = client .read_output_buffer (
262+ client .read_output (channel , timeout = timeout ), encoding = encoding )
263+ stderr = client .read_output_buffer (
264+ client .read_stderr (channel , timeout = timeout ),
265+ prefix = '\t [err]' , encoding = encoding )
266+ host_out .stdout = stdout
267+ host_out .stderr = stderr
268+ return stdout , stderr
269+
240270 def _consume_output (self , stdout , stderr ):
241271 for line in stdout :
242272 pass
0 commit comments