internal static IAdvProcess StartAdvProcess(this ICakeContext context, FilePath fileName, AdvProcessSettings settings, IAdvProcessRunner processRunner ) { if (context == null) { throw new ArgumentNullException("context"); } if (fileName == null) { throw new ArgumentNullException("fileName"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (processRunner == null) { throw new ArgumentNullException("processRunner"); } // Get the working directory. var workingDirectory = settings.WorkingDirectory ?? context.Environment.WorkingDirectory; settings.WorkingDirectory = workingDirectory.MakeAbsolute(context.Environment); // Start the process. var process = processRunner.Start(fileName, settings); if (process == null) { throw new CakeException("Could not start process."); } return process; }
public static IAdvProcess StartAdvProcess(this ICakeContext context, FilePath fileName, AdvProcessSettings settings) { if (context == null) { throw new ArgumentNullException("context"); } return StartAdvProcess(context, fileName, settings, new AdvProcessRunner(context.Environment, context.Log)); }
/// <summary> /// Sets the optional timeout for process execution /// </summary> /// <param name="settings">The process settings.</param> /// <param name="timeout">The timeout duration</param> /// <returns>The same <see cref="AdvProcessSettings"/> instance so that multiple calls can be chained.</returns> public static AdvProcessSettings SetTimeout(this AdvProcessSettings settings, int timeout) { if (settings == null) { throw new ArgumentNullException("settings"); } settings.Timeout = timeout; return(settings); }
/// <summary> /// Sets a value indicating whether the error output of an application is written to the <see cref="P:System.Diagnostics.Process.StandardError"/> stream. /// </summary> /// <param name="settings">The process settings.</param> /// <param name="redirect">true if error output should be written to <see cref="P:System.Diagnostics.Process.StandardError"/>; otherwise, false. The default is false.</param> /// <returns>The same <see cref="AdvProcessSettings"/> instance so that multiple calls can be chained.</returns> public static AdvProcessSettings SetRedirectStandardError(this AdvProcessSettings settings, bool redirect) { if (settings == null) { throw new ArgumentNullException("settings"); } settings.RedirectStandardError = redirect; return(settings); }
/// <summary> /// Sets the working directory for the process to be started. /// </summary> /// <param name="settings">The process settings.</param> /// <param name="path">The working directory for the process to be started.</param> /// <returns>The same <see cref="AdvProcessSettings"/> instance so that multiple calls can be chained.</returns> public static AdvProcessSettings UseWorkingDirectory(this AdvProcessSettings settings, DirectoryPath path) { if (settings == null) { throw new ArgumentNullException("settings"); } if (path == null) { throw new ArgumentNullException("path"); } settings.WorkingDirectory = path; return(settings); }
/// <summary> /// Starts a process using the specified information. /// </summary> /// <param name="filePath">The file name such as an application or document with which to start the process.</param> /// <param name="settings">The information about the process to start.</param> /// <returns>A process handle.</returns> public IAdvProcess Start(FilePath filePath, AdvProcessSettings settings) { if (filePath == null) { throw new ArgumentNullException("filePath"); } if (settings == null) { throw new ArgumentNullException("settings"); } // Get the arguments. var arguments = settings.Arguments ?? new ProcessArgumentBuilder(); // Log the filename and arguments. var message = string.Concat(filePath, " ", arguments.RenderSafe().TrimEnd()); _log.Verbose(Verbosity.Diagnostic, "Executing: {0}", message); // Get the working directory. var workingDirectory = settings.WorkingDirectory ?? _environment.WorkingDirectory; settings.WorkingDirectory = workingDirectory.MakeAbsolute(_environment); // Create the process start info. var info = new ProcessStartInfo(filePath.FullPath) { Arguments = arguments.Render(), WorkingDirectory = workingDirectory.FullPath, UseShellExecute = false, RedirectStandardOutput = settings.RedirectStandardOutput, RedirectStandardError = settings.RedirectStandardError }; if (settings.EnvironmentVariables != null) { foreach (string key in settings.EnvironmentVariables.Keys) { info.EnvironmentVariables[key] = settings.EnvironmentVariables[key]; } } // Start and return the process. var process = System.Diagnostics.Process.Start(info); return(process == null ? null : new AdvProcessWrapper(process, _log, arguments.FilterUnsafe)); }
/// <summary> /// Defines and sets the value of an environment variable that applies to this process and child processes /// </summary> /// <param name="settings">The settings.</param> /// <param name="name">The name of the environment variable.</param> /// <param name="value">The value of the environment variable.</param> /// <returns>The same <see cref="AdvProcessSettings"/> instance so that multiple calls can be chained.</returns> /// <exception cref="System.ArgumentNullException"><paramref name="settings"/> or <paramref name="name"/> is null.</exception> public static AdvProcessSettings WithEnvironmentVariable(this AdvProcessSettings settings, string name, string value) { if (settings == null) { throw new ArgumentNullException("settings"); } if (name == null) { throw new ArgumentNullException("name"); } settings.EnvironmentVariables[name] = value; return(settings); }
/// <summary> /// Starts a process using the specified information. /// </summary> /// <param name="filePath">The file name such as an application or document with which to start the process.</param> /// <param name="settings">The information about the process to start.</param> /// <returns>A process handle.</returns> public IAdvProcess Start(FilePath filePath, AdvProcessSettings settings) { if (filePath == null) { throw new ArgumentNullException("filePath"); } if (settings == null) { throw new ArgumentNullException("settings"); } // Get the arguments. var arguments = settings.Arguments ?? new ProcessArgumentBuilder(); // Log the filename and arguments. var message = string.Concat(filePath, " ", arguments.RenderSafe().TrimEnd()); _log.Verbose(Verbosity.Diagnostic, "Executing: {0}", message); // Get the working directory. var workingDirectory = settings.WorkingDirectory ?? _environment.WorkingDirectory; settings.WorkingDirectory = workingDirectory.MakeAbsolute(_environment); // Create the process start info. var info = new ProcessStartInfo(filePath.FullPath) { Arguments = arguments.Render(), WorkingDirectory = workingDirectory.FullPath, UseShellExecute = false, RedirectStandardOutput = settings.RedirectStandardOutput, RedirectStandardError = settings.RedirectStandardError }; if (settings.EnvironmentVariables != null) { foreach (string key in settings.EnvironmentVariables.Keys) { info.EnvironmentVariables[key] = settings.EnvironmentVariables[key]; } } // Start and return the process. var process = System.Diagnostics.Process.Start(info); return process == null ? null : new AdvProcessWrapper(process, _log, arguments.FilterUnsafe); }
/// <summary> /// Sets the arguments for the process /// </summary> /// <param name="settings">The settings.</param> /// <param name="arguments">The action used to set arguments.</param> /// <returns>The same <see cref="AdvProcessSettings"/> instance so that multiple calls can be chained.</returns> public static AdvProcessSettings WithArguments(this AdvProcessSettings settings, Action <ProcessArgumentBuilder> arguments) { if (settings == null) { throw new ArgumentNullException("settings"); } if (arguments == null) { throw new ArgumentNullException("build"); } if (settings.Arguments == null) { settings.Arguments = new ProcessArgumentBuilder(); } arguments(settings.Arguments); return(settings); }
internal static IAdvProcess StartAdvProcess(this ICakeContext context, FilePath fileName, AdvProcessSettings settings, IAdvProcessRunner processRunner) { if (context == null) { throw new ArgumentNullException("context"); } if (fileName == null) { throw new ArgumentNullException("fileName"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (processRunner == null) { throw new ArgumentNullException("processRunner"); } // Get the working directory. var workingDirectory = settings.WorkingDirectory ?? context.Environment.WorkingDirectory; settings.WorkingDirectory = workingDirectory.MakeAbsolute(context.Environment); // Start the process. var process = processRunner.Start(fileName, settings); if (process == null) { throw new CakeException("Could not start process."); } return(process); }
public static IAdvProcess StartAdvProcess(this ICakeContext context, FilePath fileName, AdvProcessSettings settings) { if (context == null) { throw new ArgumentNullException("context"); } return(StartAdvProcess(context, fileName, settings, new AdvProcessRunner(context.Environment, context.Log))); }