Пример #1
0
 internal ShellReturnInfo(ShellStartInfo startInfo, int exitCode, string standardOut, string standardErr)
 {
     m_StartInfo   = startInfo;
     m_ExitCode    = exitCode;
     m_StandardOut = standardOut;
     m_StandardErr = standardErr;
 }
Пример #2
0
        internal static ShellReturnInfo RunProcess(ShellStartInfo startInfo)
        {
            Process process = new Process();

            process.StartInfo.FileName               = startInfo.FileName;
            process.StartInfo.Arguments              = startInfo.Arguments;
            process.StartInfo.WorkingDirectory       = startInfo.WorkingDirectory;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.CreateNoWindow         = true;
            var output = new StringBuilder();

            process.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
            {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    output.AppendLine(e.Data);
                }
            });

            var error = new StringBuilder();

            process.ErrorDataReceived += new DataReceivedEventHandler((sender, e) =>
            {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    error.AppendLine(e.Data);
                }
            });

            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            process.WaitForExit();
            var exitCode = process.ExitCode;

            process.Close();

            return(new ShellReturnInfo(startInfo, exitCode, output.ToString(), error.ToString()));
        }