Comments (5)
Because the first read is finished and the second read is always blocked, it's better to check if it's done again, such as checking the prompt.
from ssh2-python.
Or you can set session to non-block, but can't be sure to receive all data
from ssh2-python.
Hi there,
Thanks for the interest. This is not an issue with the library.
channel.read
on an interactive shell (channel.shell
) will block indefinitely if there is no output to be read - this is SSH protocol behaviour. The shell is waiting for input. As it is interactive and does not send EOF, there is no indicator no more output will be sent.
The channel should be closed before trying to read again if no more commands will be sent to it. Alternatively use channel.execute
and channel.wait_eof
to determine that no more output will be sent.
If all the output needed has already been received, why is the client code trying to read more data without doing anything on the channel? There will obviously be no output from it unless something is executed first.
There is functionality in the libssh2 API to check if output is available - see session.block_directions
.
See example for use of close
, eof
and wait_eof
.
from ssh2-python.
Cheers. That clears things up. I did it this way following an online example that is obviously wrong.
I'm also trying to build in some simple error checking for an automated unsupervised script.
i.e.
- Get returned data
- Is any data returned and is it complete<< as I had it this will never be reached.
- Check returned data is correct before sending commands. (if not exit etc)
Do again for next lot of data etc
Otherwise no returned data (as some issue occurred or its wrong) the script is stuck in an infinite loop (unless there's a timeout)
An infinite loop is never a good thing without some sort of exit plan.
The example you have posted is also doing this:
# Print output
size, data = channel.read()
while size > 0:
print(data)
size, data = channel.read()
from ssh2-python.
The example is using wait_eof
and close
before reading as described above. read
returns 0 after these when all output has been consumed.
The example as present in the repo is correct for what it does, as above.
from ssh2-python.
Related Issues (20)
- Unknown error while starting the session HOT 1
- Fails to build on Python 3.11 - longintrepr.h: No such file or directory HOT 1
- ssh2-python is unable to establish connection with RHEL 9 SSHD HOT 2
- Remove Python 2 support badge HOT 1
- ed25519 key auth fails with FileError HOT 7
- `SocketRecvError` on resuming upload of partially uploaded files HOT 2
- Update libssh2 version to 1.11.0 HOT 8
- Help installing ssh2-python on alpine docker container HOT 1
- ssh2-python failed to install on windows 11 python 3.11, python 3.10 install succeded HOT 1
- Unable to install on python 3.10 macOS M1 HOT 2
- [Feature request] Musllinux wheel
- Python 3.12 support HOT 1
- Feature request: enable compression flag HOT 3
- Drop EOL Python versions (3.6, 3.7)
- Drop manylinux2010 wheels
- Migrate to OpenSSL 3
- Migrate to Cython 3
- Automate updating of vendored libraries
- scp does not write to file
- Core dump when calling session.methods()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ssh2-python.