You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to troubleshoot why shell.run is returning partial data/lines. Which is something that originally came from vagrant#11047, but it seems that what I've found has its root in this gem.
When we agree that this is rooted here, I will prepare a PR.
The example application will write a single byte at a time to stdout/stderr to test how the WinRM gem handles partial output.
The example application is executed as:
# shell_type will be :cmd or :powershellconn.shell(shell_type)do |shell|
output=shell.runcommanddo |stdout,stderr|
puts"stdout: #{stdout}"ifstdoutputs"stderr: #{stderr}"ifstderrendend
We can see unexpected differences in how the gem reports the output data.
When using the cmd shell we can see partial lines being reported. Compare the actual output:
================================================================================================================================
cmd original_shell_run
exitcode: 0
--------------------------------------------------------------------------------------------------------------------------------
stdout: #
stdout: line 0001 ###################################################
stdout: #########################################################
# line 0002 ############################################################################################################
# line 0003 ############################################################################################################
--------------------------------------------------------------------------------------------------------------------------------
stderr: #
stderr: line
stderr: 0001 ############################################################################################################
# line 0002 ############################################################################################################
# line 0003 ############################################################################################################
================================================================================================================================
With the expected result:
cmd line_buffered_shell_run
exitcode: 0
--------------------------------------------------------------------------------------------------------------------------------
stdout: # line 0001 ############################################################################################################
stdout: # line 0002 ############################################################################################################
stdout: # line 0003 ############################################################################################################
--------------------------------------------------------------------------------------------------------------------------------
stderr: # line 0001 ############################################################################################################
stderr: # line 0002 ############################################################################################################
stderr: # line 0003 ############################################################################################################
================================================================================================================================
While using the powershell shell, we can see extra new lines being reported. Compare the actual output:
powershell original_shell_run
exitcode: 0
--------------------------------------------------------------------------------------------------------------------------------
stdout: # line 0001 ############################################################################################################
stdout: # line 0002 ############################################################################################################
stdout: # line 0003 ############################################################################################################
================================================================================================================================
With the expected result:
powershell line_buffered_shell_run
exitcode: 0
--------------------------------------------------------------------------------------------------------------------------------
stdout: # line 0001 ############################################################################################################
stdout: # line 0002 ############################################################################################################
stdout: # line 0003 ############################################################################################################
The expected results we normalized by line_buffered_shell_run function, which implements my expected results.
That function essentially buffers the command output and only emit complete lines to its caller.
To execute the whole example:
In the target machine:
Install Python 3.6 at C:\Python36.
Copy the emit-partial-output.py file to the target machine C:\ directory.
In the client machine:
Install Ruby 2.7.0 and the WinRM gem 2.3.6.
Set the target machine credentials in main.rb.
Execute main.rb.
Please note that you might need to fiddle with the main.rb to make it misbehave in your machine. This is the line you want to modify:
I'm trying to troubleshoot why shell.run is returning partial data/lines. Which is something that originally came from vagrant#11047, but it seems that what I've found has its root in this gem.
When we agree that this is rooted here, I will prepare a PR.
To troubleshoot this, I've created an example at https://github.com/rgl/ruby-winrm-shell-partial-output (please look here for the whole source).
The example emit-partial-output.py application is executed by main.rb and its output is displayed.
The example application will write a single byte at a time to stdout/stderr to test how the WinRM gem handles partial output.
The example application is executed as:
We can see unexpected differences in how the gem reports the output data.
When using the
cmd
shell we can see partial lines being reported. Compare the actual output:With the expected result:
While using the
powershell
shell, we can see extra new lines being reported. Compare the actual output:With the expected result:
The expected results we normalized by
line_buffered_shell_run
function, which implements my expected results.That function essentially buffers the command output and only emit complete lines to its caller.
To execute the whole example:
C:\Python36
.emit-partial-output.py
file to the target machineC:\
directory.main.rb
.main.rb
.Please note that you might need to fiddle with the
main.rb
to make it misbehave in your machine. This is the line you want to modify:The text was updated successfully, but these errors were encountered: