Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从';System.IO.TextWriter';至';System.IO.Stream';_C# - Fatal编程技术网

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();