private void processCmd(String cmd) { Control.CheckForIllegalCrossThreadCalls = false; process = new Process(); process.StartInfo.FileName = "cmd.exe"; process.StartInfo.WorkingDirectory = "."; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.CreateNoWindow = true; //Process.Start("cmd.exe"); process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler); process.Start(); process.StandardInput.WriteLine(cmd); //process.StandardInput.WriteLine("exit"); process.BeginOutputReadLine(); using (StreamWriter sw = new StreamWriter("output.log")) { sw.WriteLine(process.StandardOutput.ReadToEnd()); } } private void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine) { if (!String.IsNullOrEmpty(outLine.Data)) { this.Invoke(ReadStdOutput, new object[] { outLine.Data }); } }