Ejemplo n.º 1
0
        public virtual void Start()
        {
            // Check to see if process is already busy
            if (Running)
            {
                throw new Exception("Process is already running.");
            }

            Dispose();

            // Get the tool executable
            string executablePath = Executable;
            if (!Path.IsPathRooted(executablePath))
            {
                executablePath = GetExecutablePath(Executable);
                if (executablePath == null)
                {
                    executablePath = Executable;
                }
            }

            // Create the process
            CurrentProcess = CreateProcess();
            CurrentProcess.StartInfo.FileName = executablePath;
            CurrentProcess.StartInfo.WorkingDirectory = WorkingDirectory;

            string args = "";
            foreach (string arg in Arguments)
            {
                if (!string.IsNullOrEmpty(args))
                {
                    args += " ";
                }
                args += arg;
            }
            CurrentProcess.StartInfo.Arguments = args;

            CurrentProcess.StartInfo.UseShellExecute = false;
            if (RedirectOutput)
            {
                CurrentProcess.StartInfo.RedirectStandardError = true;
                CurrentProcess.StartInfo.RedirectStandardOutput = true;

                listener = new ProcessHelper.ProcessListener(CurrentProcess);
                listener.StdOutNewLineReady += delegate(string line) { if (line != null) { ProcessLine(line); } };
                listener.StdErrNewLineReady += delegate(string line) { if (line != null) { ProcessErrorLine(line); } };
            }
            if (RedirectInput)
            {
                CurrentProcess.StartInfo.RedirectStandardInput = true;
            }

            // Start the process
            CurrentProcess.Start();

            if (RedirectOutput)
            {
                // Start the listener
                listener.Begin();
            }
        }
Ejemplo n.º 2
0
        public virtual void Dispose()
        {
            // Dispose of the listener
            if (listener != null)
            {
                listener.Dispose();
                listener = null;
            }

            // Dispose of the process
            if (CurrentProcess != null)
            {
                CurrentProcess.Dispose();
                CurrentProcess = null;
            }
        }