Table of Contents

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

cancellationToken CancellationToken

A timeout or cancellation.

Returns

Task<string>

The line, or null when the output has ended and nothing is left.

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.