ssh を使用してコマンドを実行したい。この例のように、 SharpSSH ライブラリ
を使用しています。
using System;
using Tamir.SharpSsh;
class Program {
static void Main(string[] args) {
string hostName = "host.foo.com";
string userName = "user";
string privateKeyFile = @"C:\privatekey.private";
string privateKeyPassword = "xxx";
SshExec sshExec = new SshExec(hostName, userName);
sshExec.AddIdentityFile(privateKeyFile, privateKeyPassword);
sshExec.Connect();
string command = string.Join(" ", args);
Console.WriteLine("command = {0}", command);
string output = sshExec.RunCommand(command);
int code = sshExec.ChannelExec.getExitStatus();
sshExec.Close();
Console.WriteLine("code = {0}", code);
Console.WriteLine("output = {0}", output);
}
}
私の問題は、実行したコマンドが出力を生成しない場合、リモート マシン上のコマンドによって返されるコードではなく、リターン コードとして -1 が返されることです。
誰かがこの問題に遭遇しましたか、それとも私が何か間違ったことをしていますか?