Exemple #1
0
        public static void StartProcess(string fileName, string arguments, string workingDirectory,
                                        EnvDTE.Project project)
        {
            Process process = null;

            try {
                Messages.ActivateMessagePane();

                process = new Process();
                process.EnableRaisingEvents = true;
                process.StartInfo           = new ProcessStartInfo
                {
                    Arguments              = arguments,
                    WorkingDirectory       = workingDirectory,
                    FileName               = HelperFunctions.FindQtDirWithTools(project) + fileName,
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true
                };

                process.Start();
                var thread = new Thread(ReadQtStandardError);
                thread.Start(new ThreadParameter
                {
                    Dte     = project.DTE,
                    Process = process
                });
                process.WaitForExit();
                thread.Join();

                if (process.ExitCode == 0)
                {
                    var index = arguments.IndexOf("-ts", System.StringComparison.OrdinalIgnoreCase);
                    var file  = "file: " + arguments + " ";
                    if (index > 0)
                    {
                        file = "file: " + arguments.Substring(index + 3) + " ";
                    }

                    Messages.PaneMessage(project.DTE,
                                         "--- (" + Path.GetFileNameWithoutExtension(fileName) + ") " + file
                                         + ": Exit Code: " + process.ExitCode);
                }
                else
                {
                    DisplayErrorMessage(process);
                }
            } catch {
                throw new QtVSException(SR.GetString("Helpers_CannotStart", process.StartInfo.FileName));
            } finally {
                if (process != null)
                {
                    process.Dispose();
                }
            }
        }