public static string Execute(string[] args, string[] scriptArgs, string logFile, string workingDirectory) { var commandArgs = new List<string>(args); if (scriptArgs.Length > 0) { commandArgs.Add("--"); commandArgs.AddRange(scriptArgs); } #if DEBUG var config = "Debug"; #else var config = "Release"; #endif var exe = Path.GetFullPath( Path.Combine("..", "..", "..", "..", "src", "ScriptCs", "bin", config, "scriptcs.exe")); var info = new ProcessStartInfo { FileName = isMono ? "mono" : exe, Arguments = isMono ? string.Concat(exe, " ", string.Join(" ", commandArgs)) : string.Join(" ", commandArgs), WorkingDirectory = workingDirectory, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true }; return info.Run(logFile); }
protected override void OnActionsExecuted() { if (this.Command == null) { throw new InvalidOperationException("The command is null."); } if (string.IsNullOrWhiteSpace(this.Command)) { throw new InvalidOperationException("The command is invalid."); } var info = new ProcessStartInfo { FileName = this.Command, Arguments = this.Args == null ? null : string.Join(" ", this.Args.Where(arg => !string.IsNullOrWhiteSpace(arg))), WorkingDirectory = this.WorkingDirectory, UseShellExecute = false, }; var argString = string.IsNullOrEmpty(info.Arguments) ? string.Empty : " " + string.Join(" ", info.Arguments); var workingDirectoryString = string.IsNullOrEmpty(info.WorkingDirectory) ? string.Empty : string.Format(CultureInfo.InvariantCulture, " with working directory '{0}'", info.WorkingDirectory); Console.WriteLine("Executing '{0}{1}'{2}...", info.FileName, argString, workingDirectoryString); info.Run(); }
private static string Execute( IEnumerable<string> args, IEnumerable<string> scriptArgs, ScenarioDirectory directory) { var commandArgs = new List<string>(args); var scriptArgsArray = scriptArgs.ToArray(); if (scriptArgsArray.Any()) { commandArgs.Add("--"); commandArgs.AddRange(scriptArgsArray); } #if DEBUG var config = "Debug"; #else var config = "Release"; #endif var exe = Path.GetFullPath( Path.Combine("..", "..", "..", "..", "src", "ScriptCs", "bin", config, "scriptcs.exe")); var info = new ProcessStartInfo { FileName = isMono ? "mono" : exe, Arguments = isMono ? string.Concat(exe, " ", string.Join(" ", commandArgs)) : string.Join(" ", commandArgs), WorkingDirectory = directory.Name, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true }; var result = info.Run(Path.GetFileName(directory.Name) + ".log"); if (result.Item1 != 0) { var message = string.Format( CultureInfo.InvariantCulture, "scriptcs.exe exited with code {0}. The output was: {1}", result.Item1.ToString(CultureInfo.InvariantCulture), result.Item2); throw new ScriptCsException(message); } return result.Item2; }