Method ReadLineAsync
- Namespace
- SshSharp
- Assembly
- SshSharp.dll
ReadLineAsync(CancellationToken)
Reads the next line of output: the text up to the next line feed, without it or a carriage return before it (a terminal ends
lines with \r\n). Once the output has ended, the text left without a line feed is the last line, and then null.
public Task<string?> ReadLineAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA timeout or cancellation.
Returns
Remarks
With a terminal, the program's output includes the echo of what was sent (a shell shows the command typed), and a prompt ends without a line feed, so a read that reaches a prompt waits for more: wait for a prompt with ExpectAsync(string, CancellationToken) instead. To run one command and read its output, RunCommandAsync(string, CancellationToken) needs neither.
Exceptions
- InvalidDataException
The line is longer than MaxBufferLength, so its start was dropped.
- OperationCanceledException
Cancelled; nothing is lost, and the partial line stays in Pending.