SshExec RunCommand returns 12 秒后退出代码为 -1(超时?)

SshExec RunCommand returns with exit code -1 after 12 seconds (timeout?)

尝试使用 Tamir.SharpSsh.SshExec 执行更长的 运行(~30 秒)sh 脚本。 (脚本在目标机器上运行良好。)~12 秒后,RunCommand 调用 returns,代码为 -1。好像是超时了,但是不知道怎么设置。

这是我使用的代码:

var ssh = new SshExec("mylinux", "myuser", "mypassword");
ssh.Connect(22);
string stdOut = "", stdErr = "";
int processExitCode = ssh.RunCommand("./longrunning.sh", ref stdOut, ref stdErr);

经过一些调试后,RunCommand 方法似乎有一个错误:如果标准输入流变空(因为脚本在较长时间内不输出任何内容)它 returns,即使脚本是仍然 运行.

作为解决方法,您可以在派生的 class 上编写固定的 RunCommand 方法,并在读取流之前主动等待 m_channel.isClosed() 变为真。