pywinrm icon indicating copy to clipboard operation
pywinrm copied to clipboard

Live stdout and stderr

Open mxmrlv opened this issue 10 years ago • 5 comments

I've added some really basic support for writing to streams. This enables to keep live track on the stdout and stderr of the remote machine. I've also added a test to test this functionality.

Also, i wanted to propose the following code change; instead of:

    stdout = stderr = ''
    return_code = -1
    for stream_node in stream_nodes:
        if stream_node.text:
            content = str(base64.b64decode(stream_node.text.encode('ascii')))
            if stream_node.attrib['Name'] == 'stdout':
                if out_stream:
                    out_stream.write(content)
                stdout += content
            elif stream_node.attrib['Name'] == 'stderr':
                if err_stream:
                    err_stream.write(content)
                stderr += content
    ...
    return stdout, stderr, return_code, command_done

I believe it would be tidier that way:

    out_string = {
        'stdout': '',
        'stderr': ''
    }
    out_stream = {
        'stdout': out_stream,
        'stderr': err_stream
    }
    return_code = -1
    for stream_node in stream_nodes:
        if stream_node.text:
            content = str(base64.b64decode(stream_node.text.encode('ascii')))            
            out_string[stream_node.attrib['Name']] += content
            if out_stream[stream_node.attrib['Name']]:
                out_stream[stream_node.attrib['Name']].write(content)
    ...
    return out_string['stdout'], out_string['stderr'], return_code, command_done

mxmrlv avatar May 31 '15 12:05 mxmrlv

Coverage Status

Coverage decreased (-0.2%) to 61.16% when pulling 3efe4c341e35017794c0e7dbcb51ecc7904cc711 on max-orlov:master into c9ce62d500007561ab31a8d0a5d417e779fb69d9 on diyan:master.

coveralls avatar Jun 01 '15 19:06 coveralls

any reason for not merging this PR?

cloneluke avatar May 31 '18 16:05 cloneluke

I was also looking for this. Please consider the merge.

kootenpv avatar Sep 26 '18 09:09 kootenpv

+1

ltamaster avatar Sep 27 '18 14:09 ltamaster