Ejemplo n.º 1
0
        /// <summary>
        /// Run the given command with arguments. Return the result in standard output.
        /// </summary>
        /// <param name="path">The path to the command to execute.</param>
        /// <param name="arguments">The arguments to pass to the command.</param>
        /// <param name="workingDirectory">The working directory for the process being launched.</param>
        /// <param name="waitForServerStart">Wait for the service to print a start message</param>
        /// <returns>The process</returns>
        private Process StartServiceProcess(
            string path,
            string arguments,
            string workingDirectory,
            bool waitForServerStart = true)
        {
            _listener = new ProcessOutputListener();
            var process   = new Process();
            var startInfo = process.StartInfo;

            startInfo.CreateNoWindow         = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            startInfo.WorkingDirectory       = workingDirectory;
            startInfo.UseShellExecute        = false;
            startInfo.FileName  = path;
            startInfo.Arguments = arguments;
            startInfo.EnvironmentVariables["PORT"] = Port.ToString(CultureInfo.InvariantCulture);
            process.OutputDataReceived            += _listener.ProcessOutput;
            process.ErrorDataReceived += _listener.ProcessError;
            process.Start();
            process.BeginOutputReadLine();
            if (waitForServerStart)
            {
                _listener.ProcessStarted.WaitOne(TimeSpan.FromSeconds(30));
            }
            return(process);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Run the given command with arguments. Return the result in standard output.
        /// </summary>
        /// <param name="path">The path to the command to execute.</param>
        /// <param name="arguments">The arguments to pass to the command.</param>
        /// <param name="workingDirectory">The working directory for the process being launched.</param>
        /// <param name="waitForServerStart">Wait for the service to print a start message</param>
        /// <returns>The process</returns>
        private Process StartServiceProcess(
            string path,
            string arguments,
            string workingDirectory,
            bool waitForServerStart = true)
        {
            _listener = new ProcessOutputListener();
            var process = new Process();
            var startInfo = process.StartInfo;
            startInfo.CreateNoWindow = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;
            startInfo.WorkingDirectory = workingDirectory;
            startInfo.UseShellExecute = false;
            startInfo.FileName = path;
            startInfo.Arguments = arguments;
#if PORTABLE
            startInfo.Environment["PORT"] = Port.ToString(CultureInfo.InvariantCulture);
#else
            startInfo.EnvironmentVariables["PORT"] = Port.ToString(CultureInfo.InvariantCulture);
#endif
            process.OutputDataReceived += _listener.ProcessOutput;
            process.ErrorDataReceived += _listener.ProcessError;
            process.Start();
            process.BeginOutputReadLine();
            if (waitForServerStart)
            {
                _listener.ProcessStarted.WaitOne(TimeSpan.FromSeconds(30));
            }
            return process;
        }