public String cmd(String cnd)
{
cnd = cnd.Trim();
String output = " ";
Console.WriteLine(cnd);
if ((cnd.Substring(0, 3).ToLower() == "cd_") && (cnd.Length > 2))
{
if (System.IO.Directory.Exists(cnd.Substring(2).Trim()))
cpath = cnd.Substring(2).Trim();
}
else
{
cnd = cnd.Insert(0, "/B /c ");
Process p = new Process();
p.StartInfo.WorkingDirectory = cpath;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = cnd;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
output = p.StandardOutput.ReadToEnd(); // output of cmd
output = (output.Length == 0) ? " " : output;
p.WaitForExit();
}
return output;
} // end cmd