I am looking for a way to help me ssh open a binary client in raspberry pi and send a few commands in that client. I try 2 ways:
SshClient sshclient = new SshClient(HostAddress, "pi", "raspberry");
sshclient.Connect();
using (SshCommand sc = sshclient.CreateCommand(
"rm /tmp/liblog.txt;
cd /home/pi;
sudo ./myClient -s ffdd::aabb:3;
setdefault;
exit"))
{
var asyncExecute = sc.BeginExecute();
sc.OutputStream.CopyTo(Console.OpenStandardOutput());
Delay(60000);
sc.EndExecute(asyncExecute);
}
sshclient.Disconnect();
sshclient.Dispose();
As you can see, I have 5 commands in here, the ssh process works ok before I run myClient. But when the client is running, the next command doesn't execute anymore. myClient is running but it doesn't do further actions. I am also trying this way and get the same result:
public void runMyClient(string HostAddress)
{
string command = " /nointeractiveinput /command \"open " + HostProtocol + "://" + HostLogin + "@" + HostAddress +
"/\" \"call cd /home/pi/\"" +
" \"call ./myClient -s ffdd::aabb:3"" +
" \"call setdefault\"";
Console.WriteLine(command);
System.Diagnostics.Process cmd = new System.Diagnostics.Process();
cmd.StartInfo.FileName = "\"C:\\Program Files (x86)\\WinSCP\\WinSCP.com\"";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.Arguments = command;
cmd.Start();
Console.WriteLine(cmd.StandardOutput.ReadToEnd());
cmd.WaitForExit();
cmd.StandardInput.Close();
cmd.Close();
}
Thanks for the help.