Stavros
Stavros

Reputation: 6140

Executing unix scripts using sshnet

I am trying to execute perl scripts on my UNIX machine, through SSH. I have managed to connect to the machine and execute "ls" and "man chmod", but when I am trying "perl /test/temp.pl" or "perl a", I don't get anything back.

The code I am using is the following

PasswordConnectionInfo connectionInfo = new PasswordConnectionInfo(host, user,pass);
using (var client = new SshClient(connectionInfo))
{
    client.Connect();
    var cmd = client.CreateCommand(script);
    string result = cmd.Execute(script);
    var reader = new StreamReader(cmd.OutputStream);
    var output = reader.ReadToEnd();
    Console.Out.WriteLine(result + "_output:" + output);
}

Anybody having the same or similar issues?

Upvotes: 1

Views: 1840

Answers (1)

Oscar Castiblanco
Oscar Castiblanco

Reputation: 1646

Try:

client.Connect();
SshCommand cmd = client.RunCommand(message);
var output =cmd.Result;

Upvotes: 5

Related Questions