Exemplo n.º 1
0
        /// <summary>
        /// Constructor that uses a specified OutputHandler
        /// </summary>
        /// <param name="filePath">the complete file path of the target executable</param>
        /// <param name="args">The arguments to supply to the process</param>
        /// <param name="handler">an instance of the OutputHandler</param>
        public CmdRunner(string filePath, string args, IOutputManager handler)
        {
            this.Log().Debug(string.Format("Creating a CmdRunner instance with these parameters: filePath= \"{0}\", args= \"{1}\", handler= \"{2}\"", filePath, args, handler.GetType().FullName));
            startInfo = new ProcessStartInfo(filePath, args);
            startInfo.UseShellExecute        = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.CreateNoWindow         = true;

            process           = new Process();
            process.StartInfo = startInfo;

            outputHandler = handler;
            process.OutputDataReceived += outputHandler.OutputDataReceived;
            process.ErrorDataReceived  += outputHandler.ErrorDataReceived;
            process.Exited             += OnExitedReceived;
            process.EnableRaisingEvents = true;
        }