fieldrndservices / libssh2-labview

A LabVIEW library for SSH client support via libssh2
Apache License 2.0
21 stars 2 forks source link

SSH read sometimes not working #48

Closed Volinger closed 2 years ago

Volinger commented 2 years ago

I am currently using the toolkit for communication with customer device. Sometimes, the behavior is following: I send the command via SSH but I don't receive any response. I was trying to debug and found that the DLL response from libssh2lv.dll in he channel read VI returns array with zeros (if I understand correctly, this means that no response was received)

When I try using desktop SSH app (putty) and try to send same SSH commands via it, I receive response as expected.

I am not sure what is the root cause, but with some commands the response is as expected, with others it is not.

One such a case which I can specify are invalid commands. For example, sending nonsense command "qwer" has the following response in putty: image

If I replicate with the toolkit, Read VI returns nothing.

Maybe my understanding of the toolkit is wrong (this seems kind of easily discoverable issue so I would expect it to be put here sooner if it was indeed an issue), in such case please let me know if I am doing something wrong.

volks73 commented 2 years ago

@Volinger, There are three "streams" to a shell: (1) standard input, stdin, (2) standard output, stdout, and (3) standard error, stderr. SSH is a "secure shell", so it also has these three streams if you establish a shell channel. The stdin stream is for sending data to a command. The Write VI are writing data to the stdin stream for the channel. The stdout stream is for reading the output from a command. The Read VI is reading from the stdout stream. Then, there is stderr, which by convention is used for displaying errors encountered while executing a command, but it is also sometimes used for displaying log messages, progress bars, or information that is not output of the command and should not be processed as data.

I suspect that you are not seeing any response because the command is writing to stderr instead of stdout. For example, the "qwer: command not found" response in PuTTY is probably from the stderr stream since it is an error and not output. Many, if not all, terminals, and terminal emulators like PuTTY, automatically read stdout and stderr from the shell and display them together in the terminal.

This toolkit is relatively low-level and does not provide for full-feature terminal for interacting with shells. This is a little out-of-scope for this project, but a full-feature terminal could be created using the building blocks of this toolkit.

I would try using the Read All Stderr.vi or the Read Stderr.vi in coordination with the Read VI. When you receive no response in stdout, is there content from reading stderr?

Volinger commented 2 years ago

@volks73 thank you very much for detailed answer! You are correct, the output which was eluding me was indeed stderr. With the Read Stderr.vi it is clearly visible. Glad to learn something new : )

volks73 commented 2 years ago

@Volinger Great! I glad I could help. It sounds like this question/issue has been answered/resolved, so I am will be closing it. Please open a new issue if you encounter anything else or you have another question.