C# 无法从';System.IO.TextWriter';至';System.IO.Stream';
此行出现错误:C# 无法从';System.IO.TextWriter';至';System.IO.Stream';,c#,C#,此行出现错误: 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, ""); sh
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();
错误:
错误3参数2:无法从“System.IO.TextWriter”转换为“System.IO.Stream”D:\applications area\test\ConsoleApplication1\ConsoleApplication1\Program.cs 19 48 ConsoleApplication1
错误4参数3:无法从“System.IO.TextWriter”转换为“System.IO.Stream”D:\applications area\test\ConsoleApplication1\ConsoleApplication1\Program.cs 19 61 ConsoleApplication1
有什么解决方案吗?
控制台。Out
是一个文本编写器,而不是流
尝试类似的方法(警告:在head中编译)
不过请注意,两次通过似乎是错误的。您可能希望将第二个或第三个参数的其他内容传递到ssh.CreateShell
。可能是Console.OpenStandardInput()
。Console.Out
是一个文本编写器,而不是一个流
尝试类似的方法(警告:在head中编译)
不过请注意,两次通过似乎是错误的。您可能希望将第二个或第三个参数的其他内容传递到ssh.CreateShell
。可能是Console.OpenStandardInput()
。我们需要知道错误消息与代码对齐的行是什么无论SshClient
是什么(您不会说),它的CreateShell
方法接受流作为第二个或第三个参数,或者两者都接受,而你却没有通过TextWriter
(Console.Out
)的类型不是从Stream
继承的。我们需要知道将错误消息与代码对齐的行是什么无论SshClient
是什么(你不说),它的CreateShell
方法接受流
,作为它的第二个或第三个参数,或者两者都接受,而你却没有通过TextWriter
(Console.Out
)的类型不是从Stream
继承的。请注意:如果这是来自codeplex的ssh客户端库,则CreateShell
将两个输出流作为参数,一个output
和一个extendedOutput
(无论是什么)。因此,两次传递stdout
可能没问题,传递stdin
可能是个坏主意。请注意:如果这是来自codeplex的ssh客户端库,那么CreateShell
将两个输出流作为参数,一个是output
,另一个是extendedOutput
(不管是什么)。因此,两次传递stdout
可能没问题,传递stdin
可能是个坏主意。
var shell = ssh.CreateShell(input, Console.Out, Console.Out, "xterm", 80, 24, 800, 600, "");
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();