darkoperator / Posh-SSH

PowerShell Module for automating tasks on remote systems using SSH
BSD 3-Clause "New" or "Revised" License
985 stars 227 forks source link

Running "terminal length 0" in SSHShellStream does not return any output #591

Open loralavandrel opened 2 months ago

loralavandrel commented 2 months ago

In version 3.1.3 once connected to Cisco Switches in SSHShellStream running "terminal length 0" with bellow commands to display multiple lines was working fine. Since 3.2.3 same commands are failing to generate any output.

$shellStream = New-SSHShellStream -SessionId $SessionID.SessionId $shellStream.WriteLine("terminal length 0") $shellStream.WriteLine("show interfaces status | include disabled.* 99 ")

I was able to force to import version 3.1.3 as a workaround.

darkoperator commented 2 months ago

This is at the ssh.net library level. When you create the stream and do a read don you get output?

loralavandrel commented 2 months ago

In version 3.1.3 running mentioned commands in output we have a response from the devices, so the output looks like:

[switch_name]#terminal length 0
[switch_name]#show interfaces status | include disabled.* 99
table of interfaces with specific condition

Running the same in 3.2.3 does return only below output:

[switch_name]#terminal length 0
[switch_name]#show interfaces status | include disabled.* 99

If I remove "terminal length 0" command in 3.2.3 I do have an output of interfaces however they have been truncated as the output is bigger than default 24 lines.

darkoperator commented 2 months ago

what would happen if you added a

Start-Sleep -Seconds 2

before the

$shellStream.WriteLine("terminal length 0")

It could be it takes now longer for the shellstream to be created with all the updates the library did and we are hitting a race condition

loralavandrel commented 2 months ago

Adding "Start-Sleep -Seconds 3" did not resolve it. I have output generated however I do not see all of the output that is generated like in 3.1.3 version. In 3.2.3 I can only see the commands that were provided without the generated output from "show interfaces status | include disabled.* 99" command.

darkoperator commented 2 months ago

Wonder if it is related to this, since you are using the .Net objects it seems to be more of a library issue StreamReader on ShellStream runs into a lock · Issue #1485 · sshnet/SSH.NETgithub.com