I want to run a command using ssh.
I am using the SharpSSH library, as in this example:
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);
}
}
My problem is that when the command I run produces no output, I get -1 as return code, instead of the code returned by the command on the remote machine.
Has someone encountered this problem, or am I doing something wrong?