【问题标题】:Responding to command prompts in SSH.NET响应 SSH.NET 中的命令提示符
【发布时间】:2019-03-14 20:56:34
【问题描述】:

我想中断我的输出日志线程来“确认”一个动作。 比如我要安装php,所以我输入sudo apt-get install php。我必须用y 确认,我知道我可以写sudo apt-get install php -y。我在执行脚本时遇到了同样的问题,我必须填写必要的信息。

using (var client = new SshClient(ip, Convert.ToInt16(port), username, password))
{
    client.Connect();

    var command = client.CreateCommand((txtCommand.Text));
    var result = command.BeginExecute();

    //log vps output 
    using (var reader =
       new StreamReader(command.OutputStream, Encoding.UTF8, true, 1024, true))
    {
        while (!result.IsCompleted || !reader.EndOfStream)
        {
            string line = reader.ReadLine();
            if (line != null)
            {
                     txtOutput1.Invoke(
                         (MethodInvoker)(() =>
                     txtOutput1.AppendText(line + Environment.NewLine)));
            }
        }
    }

    command.EndExecute(result);
    client.Disconnect();
}

那么如何中断线程执行新命令来解决read命令呢?

【问题讨论】:

  • 什么是“确认某事”?搜索未在编程/开发/计算机环境中提供结果。

标签: c# .net visual-studio ssh ssh.net


【解决方案1】:

使用使用 shell 结构的输入重定向来为脚本提供输入。

喜欢:

echo input | ./your_script.sh

【讨论】:

    猜你喜欢
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 2013-03-23
    • 2023-03-20
    • 1970-01-01
    相关资源
    最近更新 更多