Method ExpectAsync
- Namespace
- SshSharp
- Assembly
- SshSharp.dll
ExpectAsync(string, CancellationToken)
Waits until the output contains text (an ordinal match).
public Task<SshExpectMatch> ExpectAsync(string text, CancellationToken cancellationToken = default)
Parameters
textstringThe text to wait for, for example a prompt.
cancellationTokenCancellationTokenA timeout or cancellation.
Returns
- Task<SshExpectMatch>
The output before the match, and the match; both are consumed.
Exceptions
- EndOfStreamException
The output ended without the text appearing (Pending holds what came).
- OperationCanceledException
Cancelled; nothing is lost, and the output read so far stays in Pending.
ExpectAsync(Regex, CancellationToken)
Waits until the output matches pattern.
public Task<SshExpectMatch> ExpectAsync(Regex pattern, CancellationToken cancellationToken = default)
Parameters
patternRegexThe pattern to wait for, for example
new Regex(@"[$#] $")for a shell prompt.cancellationTokenCancellationTokenA timeout or cancellation.
Returns
- Task<SshExpectMatch>
The output before the match, and the match with its groups; both are consumed.
Exceptions
- EndOfStreamException
The output ended without a match (Pending holds what came).
- OperationCanceledException
Cancelled; nothing is lost, and the output read so far stays in Pending.
- RegexMatchTimeoutException
Matching took longer than the pattern's MatchTimeout; the output stays in Pending.