1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| private static void StartAConsoleProcess(string exePath, params string[] cmdText) { Process p = new Process(); p.StartInfo = new ProcessStartInfo(exePath); p.StartInfo.UseShellExecute = false;
if (exePath.Contains(Path.DirectorySeparatorChar)) { var file = new FileInfo(exePath); p.StartInfo.WorkingDirectory = file.Directory.FullName; }
p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.OutputDataReceived += YgcApi_OutputDataReceived; p.ErrorDataReceived += YgcApi_ErrorDataReceived; p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); if (cmdText.Length > 0) { foreach (var item in cmdText) { p.StandardInput.WriteLine(item); p.StandardInput.AutoFlush = true; } } }
|