cannot convert from 'System.IO.TextWriter' to 'S

本文关键字:TextWriter to IO System convert cannot from | 更新日期: 2023-09-27 18:15:05

        var ssh = new SshClient("ip", "user", "pass");
        var input = new MemoryStream(Encoding.ASCII.GetBytes("exit'r'n"));
        var shell = ssh.CreateShell(input, Console.Out, Console.Out, "xterm", 80, 24, 800, 600, "");
        shell.Stopped += delegate(object sender, EventArgs e)
        {
            Console.WriteLine("'nDisconnected...");
        };
        shell.Start();
        Thread.Sleep(1000 * 1000);
        shell.Stop();

本行错误:

var shell = ssh.CreateShell(input, Console.Out, Console.Out, "xterm", 80, 24, 800, 600, "");

错误:错误3参数2:不能从System.IO转换。TextWriter' to 'System.IO。Stream' D:'applications area'test'ConsoleApplication1'ConsoleApplication1'Program.cs 19 48 ConsoleApplication1

错误4参数3:无法从System.IO转换。TextWriter' to 'System.IO。Stream' D:'applications area'test'ConsoleApplication1'ConsoleApplication1'Program.cs 19 61 ConsoleApplication1

cannot convert from 'System.IO.TextWriter' to 'S

Console.OutTextWriter,不是流。

尝试这样做(警告:编译在头部)

Stream stdout = Console.OpenStandardOutput();
var ssh = new SshClient("ip", "user", "pass");
var input = new MemoryStream(Encoding.ASCII.GetBytes("exit'r'n"));
var shell = ssh.CreateShell(input, stdout, stdout, "xterm", 80, 24, 800, 600, "");
shell.Stopped += delegate(object sender, EventArgs e)
{
    Console.WriteLine("'nDisconnected...");
};
shell.Start();
Thread.Sleep(1000 * 1000);
shell.Stop();

不过要注意传递它两次似乎是错误的。您可能希望为ssh.CreateShell的第二个或第三个参数传递其他内容。可能是Console.OpenStandardInput()