3

I am working on creating a GUI to interface with a Citrix XEN server. I dont know how to execute commands from my within my application on my widows system on the XEN Server. I was thinking using SSH but again I dont know how. Does anyone have an example of how to do this? How to establish a SSH tunnel when the user pushes a button? I want to be able to run the command xe vm-list and then display the output in a label. Thats just to start my next one will be to create a VM and name is what the user wants, but for now I just need to figure out how to execute commands on the XEN Server.

mikerobi
  • 20,527
  • 5
  • 46
  • 42
user770022
  • 2,899
  • 19
  • 52
  • 79

2 Answers2

2

I have used SharpSSH with great success.

This can be downloaded from http://www.tamirgal.com/blog/page/SharpSSH.aspx.

Pieter van Ginkel
  • 29,160
  • 8
  • 71
  • 111
1

Finding yourself an ssh component will allow you to do more meaningful things, but at the base level, you can do something like this:

public void ExecuteExternalCommand(string command)
{
 try
 {
  // process start info
  System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
  processStartInfo.RedirectStandardOutput = true;
  processStartInfo.UseShellExecute = false;
  processStartInfo.CreateNoWindow = true; // Don't show console

  // create the process
  System.Diagnostics.Process process = new System.Diagnostics.Process();
  process.StartInfo = processStartInfo;
  process.Start();

  string output = process.StandardOutput.ReadToEnd();
  Console.WriteLine(output);
 }
 catch (Exception exception)
 {
  //TODO: something Meaninful
 }
}

Which will let you run arbitrary external executables via the cmd.exe interface and then respond to it.

Here's some Links:

lscoughlin
  • 2,327
  • 16
  • 23