diff --git a/README.md b/README.md index 0ec451e..be5d474 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ class RemoteProcess : IDisposable { // Read from the remote process. ValueTask<(bool isError, string? line)> ReadLineAsync(bool readStdout = true, bool readStderr = true, CancellationToken cancellationToken = default); - ValueTask<(string? stdout, string? stderr)> ReadToEndAsStringAsync(bool readStdout = true, bool readStderr = true, CancellationToken cancellationToken = default); + ValueTask<(string stdout, string stderr)> ReadToEndAsStringAsync(bool readStdout = true, bool readStderr = true, CancellationToken cancellationToken = default); IAsyncEnumerable<(bool isError, string line)> ReadAllLinesAsync(bool readStdout = true, bool readStderr = true, CancellationToken cancellationToken = default); ValueTask ReadToEndAsync(Stream? stdoutStream, Stream? stderrStream, CancellationToken? cancellationToken); ValueTask<(bool isError, int bytesRead)> ReadAsync(Memory? stdoutBuffer, Memory? stderrBuffer, CancellationToken cancellationToken = default); diff --git a/src/Tmds.Ssh/RemoteProcess.cs b/src/Tmds.Ssh/RemoteProcess.cs index 9b0ed68..1e90c35 100644 --- a/src/Tmds.Ssh/RemoteProcess.cs +++ b/src/Tmds.Ssh/RemoteProcess.cs @@ -357,7 +357,7 @@ public ValueTask WaitForExitAsync(CancellationToken cancellationToken = default) return ReadToEndAsync(null, null, null, null, cancellationToken); } - public async ValueTask<(string? stdout, string? stderr)> ReadToEndAsStringAsync(bool readStdout = true, bool readStderr = true, CancellationToken cancellationToken = default) + public async ValueTask<(string stdout, string stderr)> ReadToEndAsStringAsync(bool readStdout = true, bool readStderr = true, CancellationToken cancellationToken = default) { CheckReadMode(ReadMode.ReadChars); @@ -367,8 +367,8 @@ public ValueTask WaitForExitAsync(CancellationToken cancellationToken = default) if (readType == ProcessReadType.ProcessExit) { _readMode = ReadMode.Exited; - string? stdout = readStdout ? _stdoutBuffer.BuildString() : null; - string? stderr = readStderr ? _stderrBuffer.BuildString() : null; + string stdout = readStdout ? _stdoutBuffer.BuildString()! : ""; + string stderr = readStderr ? _stderrBuffer.BuildString()! : ""; return (stdout, stderr); } } diff --git a/test/Tmds.Ssh.Tests/KerberosTests.cs b/test/Tmds.Ssh.Tests/KerberosTests.cs index 7d97b7d..3dd24d4 100644 --- a/test/Tmds.Ssh.Tests/KerberosTests.cs +++ b/test/Tmds.Ssh.Tests/KerberosTests.cs @@ -96,9 +96,9 @@ await _kerberosExecutor.RunAsync( { using var process = await client.ExecuteAsync("whoami"); - (string? stdout, string? stderr) = await process.ReadToEndAsStringAsync(); + (string stdout, string stderr) = await process.ReadToEndAsStringAsync(); Assert.Equal(0, process.ExitCode); - Assert.Equal(userName, stdout?.Trim()); + Assert.Equal(userName, stdout.Trim()); } }, [ connectionName, targetName ?? string.Empty, _sshServer.KnownHostsFilePath, userName, _sshServer.TestKerberosCredential.UserName, _sshServer.TestKerberosCredential.Password ] @@ -163,14 +163,14 @@ await _kerberosExecutor.RunAsync( { using var process = await client.ExecuteAsync("whoami"); - (string? stdout, string? stderr) = await process.ReadToEndAsStringAsync(); + (string stdout, string stderr) = await process.ReadToEndAsStringAsync(); Assert.Equal(0, process.ExitCode); - Assert.Equal(userName, stdout?.Trim()); + Assert.Equal(userName, stdout.Trim()); } { using var process = await client.ExecuteAsync("klist -f"); - (string? stdout, string? stderr) = await process.ReadToEndAsStringAsync(); + (string stdout, string stderr) = await process.ReadToEndAsStringAsync(); if (requestDelegate) { diff --git a/test/Tmds.Ssh.Tests/RemoteProcessTests.cs b/test/Tmds.Ssh.Tests/RemoteProcessTests.cs index 5bdc5a1..8d1e3b0 100644 --- a/test/Tmds.Ssh.Tests/RemoteProcessTests.cs +++ b/test/Tmds.Ssh.Tests/RemoteProcessTests.cs @@ -294,9 +294,9 @@ public async Task ReadToEndAsStringAsync(bool readStdout, bool readStderr) await process.WriteLineAsync("echo -n 'hello stderr2' >&2"); await process.WriteLineAsync("exit 0"); - (string? stdout, string? stderr) = await process.ReadToEndAsStringAsync(readStdout, readStderr); - Assert.Equal(readStdout ? "hello stdout1hello stdout2" : null, stdout); - Assert.Equal(readStderr ? "hello stderr1hello stderr2" : null, stderr); + (string stdout, string stderr) = await process.ReadToEndAsStringAsync(readStdout, readStderr); + Assert.Equal(readStdout ? "hello stdout1hello stdout2" : "", stdout); + Assert.Equal(readStderr ? "hello stderr1hello stderr2" : "", stderr); } [Theory]