Skip to content
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 properly detect command completion vs ExtendedOutputStream content? #1551

Open
msdobrescu opened this issue Dec 5, 2024 · 1 comment

Comments

@msdobrescu
Copy link

Hi, I need to implement commands over ssh and I've found this: https://stackoverflow.com/questions/31587924/ssh-net-real-time-command-output-monitoring#31637155

I've tried those, but one of the streams never reaches end (EndOfStream == true).
How should this be implemented if I need to capture the output of both streams and detect when there is no more new data on them?

@Rob-Hague
Copy link
Collaborator

it would be unexpected if one stream is closed but the other isn't. Here is a test example of reading both streams. In this case, it calls Execute which returns stdout (OutputStream) as a string

[TestMethod]
public void Test_Execute_ExtendedOutputStream()
{
using (var client = new SshClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
{
#region Example SshCommand CreateCommand Execute ExtendedOutputStream
client.Connect();
using var cmd = client.CreateCommand("echo 12345; echo 654321 >&2");
using var reader = new StreamReader(cmd.ExtendedOutputStream);
Assert.AreEqual("12345\n", cmd.Execute());
Assert.AreEqual("654321\n", reader.ReadToEnd());
client.Disconnect();
#endregion
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants