How to return data line by line - WeOnlyDo Discussion board

How to return data line by line (wodSSH / wodSSH.NET)

by Ernesto Cullen, Wednesday, November 19, 2014, 19:04 (3657 days ago) @ Jasmine

ok, I will try with both modes to see which one is better for our app. In blocking mode, how do you define the loop? In the code below I use DataReady property, but in the help it says explicitly that this is not reliable. What should I use then?
Could you write a small example using the non blocking mode?


...
var linesReceived = 0;
ssh.Command = "ls -alR /";
try
{
    ssh.Connect(hostname, port);
    while (true)
    {
        var tempLine = ssh.ReceiveLine();
        Console.WriteLine("{0} {1}", ++linesReceived, tempLine);
        if (ssh.DataReady == 0)
            break;
    }
}
catch (Exception ex)
{
    DebugMessage(String.Format("Connection exception {0}: {1}", ex.GetType(), ex.Message));
    throw;
}

The exception code needs more work, at least I should capture the 'None found' exception (is it an Exception instance or some ENoneFoundException or something like that?) to cover the case when the command output does not include EOL at the end.

thanks

Ernesto


Complete thread: