private StringBuilder receivedResponse = new StringBuilder(); private void SendCommand(Command) { System.Diagnostics.Process proc proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = "cmd"; proc.StartInfo.Arguments = " /C " + Command; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardError = true; proc.Start(); proc.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(OnOutputDataReceived); proc.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(OnErrorDataReceived); proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); proc.WaitForExit(5000); response = receivedResponse.ToString(); // Custom method to display the response on the UI. ShowResponse(response, ELogLevel.Debug); } void OnOutputDataReceived(object sendingProcess, System.Diagnostics.DataReceivedEventArgs args) { if (!string.IsNullOrEmpty(args.Data)) { lock (this.receivedResponse) { string s = args.Data; this.receivedResponse.AppendLine(s); } } }