New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to forward stdin, stdout *and* stderr #189
Comments
Ah actually I just looked at the source and it looks like I should pass 0 for both. I will try that. Might be worth adding a named constant, or even a |
This worked well for me. I haven't thought much about exactly what happens when the various channels are closed, e.g. should it end when stdin closes etc.
|
Note that even though the streams, channels etc. are |
Oh, damn. That's unfortunate. Although I did try this and it actually seemed to work for me - I wrote a trivial program that reads from stdin and writes that to stdout lowercased and stderr uppercased. Then I executed it on a remote server using the above code and fed some data in via stdout. It seemed to work. I can't see how it would work at all if the first Is there no way to do this with this library then? |
What I do in wezterm is poll the underlying socket for read/write events and then perform the corresponding read/write in non-blocking mode; that way none of the threads is blocking the others while they are waiting. |
Hmm yeah that doesn't sound ideal. Quite a limitation! Incidentally this seems to be quite an old request (#22). |
I ended up reimplementing this part of my program (which is a completely standalone executable) in Go - it has a really great SSH library, and makes forwarding stdin/out/err completely trivial:
Hopefully we'll get a great native SSH & SFTP library for Rust one day! Maybe Thrussh, but at the moment it still has C dependencies, is completely undocumented and doesn't include SFTP support. |
I change some of your code, and work well, it just like your go code (i had try it too) ! Except that it can not hanle control code like Tab key. No delay, No block, but three busy loop( as you know three io::copy is three busy loop too).
|
It looks like you are trying to do a non-blocking spin-loop style read of I guess if you set the streams to non-blocking mode it will work (if you can even do that for these streams) but nobody wants 200% CPU usage just reading idle streams. |
Thanks for your tips. `
} |
I want to execute a command remotely and then forward all three streams - stdin, stdout and stderr. This is closely related to #128, but none of the solutions there seem very good. I don't want a busy loop, and this solution looks like it will delay stdin until stdout data is available.
My theory is that the basic idea is to start a thread for each channel:
This almost works. Because
channel.stderr()
exists and returns aStream
that isSend
andSync
. However there doesn't seem to be a way to do the same thing for stdin and stdout - there is noChannel::stdout()
. The channel itself implementsRead
/Write
, but I can't mutably borrow it twice in different threads.There is
stream()
which looks like it might be useful, but I'm not sure what to pass it to get stdin/out.Any hints?
The text was updated successfully, but these errors were encountered: