Skip to content

Commit

Permalink
FEAT: hack to allow for streamed output.
Browse files Browse the repository at this point in the history
  • Loading branch information
cournape committed Mar 22, 2013
1 parent 57d1b54 commit 0a6773e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions winrm/winrm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ def get_command_output(self, shell_id, command_id):
# is either :stdout or :stderr. The reason it is in an Array so so we can get the output in the order it ocurrs on
# the console.
"""
stdout_buffer, stderr_buffer = [], []
command_done = False
while not command_done:
stdout, stderr, return_code, command_done = \
self._raw_get_command_output(shell_id, command_id)
stdout_buffer.append(stdout)
stderr_buffer.append(stderr)
return "".join(stdout_buffer), "".join(stderr_buffer), return_code

def _raw_get_command_output(self, shell_id, command_id):
node = xmlwitch.Builder(version='1.0', encoding='utf-8')
with node.env__Envelope(**self._namespaces):
with node.env__Header:
Expand Down Expand Up @@ -286,11 +296,7 @@ def get_command_output(self, shell_id, command_id):
# <rsp:ExitCode>0</rsp:ExitCode>
# </rsp:CommandState>
command_done = len([node for node in root.findall('.//*') if node.get('State', '').endswith('CommandState/Done')]) == 1
if not command_done:
new_stdout, new_stderr, ignored_code = self.get_command_output(shell_id, command_id)
stdout += new_stdout
stderr += new_stderr
else:
if command_done:
return_code = int(next(node for node in root.findall('.//*') if node.tag.endswith('ExitCode')).text)

return stdout, stderr, return_code
return stdout, stderr, return_code, command_done

0 comments on commit 0a6773e

Please sign in to comment.