Ejemplo n.º 1
0
        /// <summary>
        /// Starts the process.
        /// </summary>
        /// <param name="command">The process filename.</param>
        /// <param name="arguments">The command line arguments to
        /// pass to the command.</param>
        public void Start(string command, string arguments)
        {
            process = new Process();
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.FileName               = command;
            process.StartInfo.WorkingDirectory       = workingDirectory;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.Arguments              = arguments;

            if (ProcessExited != null)
            {
                process.EnableRaisingEvents = true;
                process.Exited += OnProcessExited;
            }

            bool started = false;

            try {
                process.Start();
                started = true;
            } finally {
                if (!started)
                {
                    process.Exited -= OnProcessExited;
                    process         = null;
                }
            }

            standardOutputReader = new OutputReader(process.StandardOutput);
            if (OutputLineReceived != null)
            {
                standardOutputReader.LineReceived += new LineReceivedEventHandler(OnOutputLineReceived);
            }

            standardOutputReader.Start();

            standardErrorReader = new OutputReader(process.StandardError);
            if (ErrorLineReceived != null)
            {
                standardErrorReader.LineReceived += new LineReceivedEventHandler(OnErrorLineReceived);
            }

            standardErrorReader.Start();
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Starts the process.
		/// </summary>
		/// <param name="command">The process filename.</param>
		/// <param name="arguments">The command line arguments to
		/// pass to the command.</param>
		public void Start(string command, string arguments)
		{	
			process = new Process();
			process.StartInfo.CreateNoWindow = true;
			process.StartInfo.FileName = command;
			process.StartInfo.WorkingDirectory = workingDirectory;
			process.StartInfo.RedirectStandardOutput = true;
			process.StartInfo.RedirectStandardError = true;
			process.StartInfo.UseShellExecute = false;
			process.StartInfo.Arguments = arguments;
			
			if (ProcessExited != null) {
				process.EnableRaisingEvents = true;
				process.Exited += OnProcessExited;
			}

			bool started = false;
			try {
				process.Start();
				started = true;
			} finally {
				if (!started) {
					process.Exited -= OnProcessExited;			
					process = null;
				}
			}
				
			standardOutputReader = new OutputReader(process.StandardOutput);
			if (OutputLineReceived != null) {
				standardOutputReader.LineReceived += new LineReceivedEventHandler(OnOutputLineReceived);
			}
			
			standardOutputReader.Start();
			
			standardErrorReader = new OutputReader(process.StandardError);
			if (ErrorLineReceived != null) {
				standardErrorReader.LineReceived += new LineReceivedEventHandler(OnErrorLineReceived);
			}
			
			standardErrorReader.Start();
		}