12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
-
- namespace NRKernal
- {
- using System.Diagnostics;
- using System.Text;
-
- public static class ShellHelper
- {
-
-
-
-
-
- public static void RunCommand(string fileName, string arguments, out string output, out string error)
- {
- using (var process = new Process())
- {
- var startInfo = new ProcessStartInfo(fileName, arguments);
- startInfo.UseShellExecute = false;
- startInfo.RedirectStandardError = true;
- startInfo.RedirectStandardOutput = true;
- startInfo.CreateNoWindow = true;
- process.StartInfo = startInfo;
- var errorBuilder = new StringBuilder();
- process.ErrorDataReceived += (sender, ef) => errorBuilder.AppendLine(ef.Data);
- process.Start();
- process.BeginOutputReadLine();
- process.BeginErrorReadLine();
- process.WaitForExit();
- var existcode = process.ExitCode;
- process.Close();
-
- output = existcode.ToString();
- error = errorBuilder.ToString().Trim();
- }
- }
-
-
-
- public static void RunCommand(string fileName, string arguments)
- {
- using (var process = new Process())
- {
- var startInfo = new ProcessStartInfo(fileName, arguments);
- startInfo.CreateNoWindow = false;
- process.StartInfo = startInfo;
- process.Start();
- }
- }
- }
- }
|