示例#1
0
        public static int StartProcess(
            this ICakeContext context,
            FilePath fileName,
            ProcessSettings settings,
            out IEnumerable <string> redirectedStandardOutput,
            out IEnumerable <string> redirectedErrorOutput)
        {
            var process = StartAndReturnProcess(context, fileName, settings);

            // Wait for the process to stop.
            if (settings.Timeout.HasValue)
            {
                if (!process.WaitForExit(settings.Timeout.Value))
                {
                    throw new TimeoutException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  "Process TimeOut ({0}): {1}",
                                  settings.Timeout.Value,
                                  fileName));
                }
            }
            else
            {
                process.WaitForExit();
            }

            redirectedStandardOutput = settings.RedirectStandardOutput
                ? process.GetStandardOutput()
                : null;

            redirectedErrorOutput = settings.RedirectStandardError
                ? process.GetStandardError()
                : null;

            // Return the exit code.
            return(process.GetExitCode());
        }
示例#2
0
 public static int StartProcess(this ICakeContext context, FilePath fileName, ProcessSettings settings)
 {
     return(StartProcess(context, fileName, settings, out var redirectedOutput));
 }
示例#3
0
        public static IProcess StartAndReturnProcess(this ICakeContext context, FilePath fileName, ProcessSettings settings)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (!settings.NoWorkingDirectory)
            {
                // Set the working directory.
                var workingDirectory = settings.WorkingDirectory ?? context.Environment.WorkingDirectory;
                settings.WorkingDirectory = workingDirectory.MakeAbsolute(context.Environment);
            }

            // Start the process.
            var process = context.ProcessRunner.Start(fileName, settings);

            if (process == null)
            {
                throw new CakeException("Could not start process.");
            }

            return(process);
        }
示例#4
0
        public static int StartProcess(this ICakeContext context, FilePath fileName, ProcessSettings settings)
        {
            IEnumerable <string> redirectedOutput;

            return(StartProcess(context, fileName, settings, out redirectedOutput));
        }