首页 > 解决方案 > 使用 ssh.net 我无法获得输出

问题描述

运行脚本后我没有得到任何输出。请有人帮助我为什么输出显示为空。

我可以看到它连接到服务器。

namespace WebApplication10.helpers
{
    public class service
    {
        public static List<Servicestatus> serviceadd(servername,UserName,Password)
        {
            List<Servicestatus> results = new List<Servicestatus>();
            try
            {
                using (var client = new SshClient(servername, UserName, Password))
                {
                    client.Connect();

                    SshCommand strOutput = client.CreateCommand("service --status-all");
                    var str = strOutput.Execute();

                    Console.WriteLine(str)

                    client.Disconnect();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine( e.Message );
            }
        }
    }
}

标签: c#.netssh

解决方案


你会得到回应yourCommand.Result

SshCommand command = client.CreateCommand("service --status-all");
command.Execute();
Console.WriteLine(command.Result)

推荐阅读