Comments (7)
In the second block of code, it looks to me like it is doing the right thing, assuming that the next output after what is shown here is a prompt of some kind, without a newline at the end. You are calling readline()
on stdout, so it will remain blocking waiting for a complete line or for end-of-file on stdout before it returns.
As for the first error you saw, that appears to be a bug in asyncio on Windows. There's a reference to _empty_waiter in _ProactorBasePipeTransport._force_close, but _empty_waiter is only set in _ProactorBaseWritePipeTransport and _ProactorDatagramTransport and not in _ProactorReadPipeTransport. The assignment of _empty_waiter to None
should probably happen in the _ProactorBasePipeTransport constructor instead of _ProactorBaseWritePipeTransport and _ProactorDatagramTransport, so that it will always exist before being referenced in _force_close
.
from asyncssh.
In the second block of code, it looks to me like it is doing the right thing, assuming that the next output after what is shown here is a prompt of some kind, without a newline at the end. You are calling
readline()
on stdout, so it will remain blocking waiting for a complete line or for end-of-file on stdout before it returns.As for the first error you saw, that appears to be a bug in asyncio on Windows. There's a reference to _empty_waiter in _ProactorBasePipeTransport._force_close, but _empty_waiter is only set in _ProactorBaseWritePipeTransport and _ProactorDatagramTransport and not in _ProactorReadPipeTransport. The assignment of _empty_waiter to
None
should probably happen in the _ProactorBasePipeTransport constructor instead of _ProactorBaseWritePipeTransport and _ProactorDatagramTransport, so that it will always exist before being referenced in_force_close
.
Thanks for your swift response.
For the second code block,when it's
print(await SSHClientProcess.stdout.read(1),end='')
or
print(await SSHClientProcess.stdout.readexactly(1),end='')
it will get stuck too.
from asyncssh.
Yes - both read() and readexactly() will eventually block as well. The only difference is that you should see the prompt get output with those, where you wouldn't see the prompt get output in the readline() case. Since the remote system is waiting for input after that, you can't just keep reading. You need to provide some input or write EOF on stdin if you want to see any more output.
from asyncssh.
if it works well,It should output root@OpenWrt:~#
.But when I use debug mode,it will get stuck at stdout.read
.
I have tried to use stdin.write
to write both 'll\n'
and like 'pwd\n'
, but there is no any response when I debug.
Just using keyboard fails too.
from asyncssh.
On some remote systems, trying to write the input before the prompt comes up won't work. That input gets thrown away by the remote system, since it wasn't actively reading input at the time. I don't know if that's the case here or not, but if you write the input before seeing the prompt, that may be the source of the problem. If you know what the prompt looks like, you can use readuntil()
to read data which matches the prompt, and it should be safe after that returns to send your input.
If you're not seeing the prompt even after switching to read()
or readexactly()
, that may be a stdio buffering issue. Try adding something like sys.stdout.flush()
after your call to print()
. I think stdout is normally line-buffered by default.
from asyncssh.
Sorry,I don't find a method like flush()
in stdout. But I tried to use stdout.feed_data("something")
,and the stdout.read()
works well. So I guess it may be something wrong with the connection so there is no data in stdout.
from asyncssh.
The flush()
I mentioned was on sys.stdout (which print is
outputting to), not the process stdout.
Are you trying to mix process redirection (assigning the stdin
, stdout
, and stderr
on a process or run()
command) with doing your own I/O? that doesn't really work as you can't control the ordering of the data -- you can use automatic redirection or manual I/O, but not both at once. You can provide some initial input through the input
argument, but doesn't work well for interactive sessions, as AsyncSSH sends EOF after sending the requested input.
If you are doing manual I/O, you should be doing stdin.write() on the process, but that will only work if you don't already have stdin redirected to something else (like sys.stdin).
As for why things might not be working interactively using the redirects, are you requesting a PTY on the SSH session? If not, trying to send data from a terminal might not work well. For instance, you may have issues like needing to type Ctrl-J instead of Enter to end a line. You can request a PTY by passing in the term_type
argument. For instance, term_type='ansi'
.
from asyncssh.
Related Issues (20)
- Asyncssh for docker run HOT 3
- Setting terminal size of a sub process HOT 28
- v2.14.2 has interop problem with netdev running with python 3.8 HOT 3
- AsyncSSH Connection to Cisco Router with Jump Host HOT 6
- Why is the loop waiting for command execution endless? HOT 2
- asyncssh raises ValueError if `SetEnv` is used in SSH config HOT 13
- 2.14.1+ fails to rekey with OpenSSH <= 6 HOT 7
- asyncio.run(asyncssh.connect()) raises ValueError: a coroutine was expected, got <asyncssh.misc._ACMWrapper object ..> HOT 4
- OOM when redirecting large stdout to asyncio Process HOT 11
- SFTP preserve always follows symlinks HOT 5
- Allow host key rotation, implement [email protected] / [email protected] request HOT 8
- Logging error in SFTP copy with `Sequence[PurePath]` HOT 4
- Intermittent failure to read output when using SSHClientProcess.wait HOT 6
- Suppress deprecation warnings from Cyrptography 43.0.0 when importing ARC4 and TripleDES HOT 7
- Parsing breaks ProxyCommand executable path on Windows. HOT 8
- SSH connection issue when upgrading to asyncssh 2.15.0 HOT 16
- Suggestion Re Simple Client Example: HOT 1
- GSSAPI limited to single user principal HOT 5
- Spurious calls to `SSHChannel._cleanup` starting from AsyncSSH 2.15.0 HOT 3
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 asyncssh.