/// (c) 2007 James A Briant /// /// Permission is granted to use or modify this source code provided that /// a) this notice is kept intact /// b) if you make any modications to this file you assign the /// copyright of those modifications to James Briant. /// c) you acknowledge that Mr. Briant offers no warranty /// and will not be liable for any loss, damages, time, etc. /// /// Any doubt, email me: firstname (nospace) lastname at persuasivesoftware.com /// /// This package is inspired by Noel Llopis's P4AddIn (also available from /// the perforce public depot), and also a similar package that I developed /// at Bunkspeed, Inc ( www.bunkspeed.com ) makers of real-time raytracing /// tools that anyone case use. using System.Diagnostics; using DevDriven.P4Vs; namespace DevDriven.P4Vs { public interface ICmdExec { int Exec(string cmd, string args, string cwd, out string result, out string errors); int Exec(string cmd, string args, string cwd); void Start(string cmd, string args, string cwd); } class CommandExec : ICmdExec { private readonly ILogger log; public CommandExec(ILogger log) { this.log = log; } public int Exec(string cmd, string args, string cwd, out string result, out string errors) { log.WriteLine(1, "Executing: {0} {1}", cmd, args); ProcessStartInfo psi = new ProcessStartInfo(cmd, args); psi.CreateNoWindow = true; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.UseShellExecute = false; psi.WorkingDirectory = cwd; // Needed for P4CONFIG to work Process process = Process.Start(psi); process.WaitForExit(); result = process.StandardOutput.ReadToEnd(); errors = process.StandardError.ReadToEnd(); return process.ExitCode; } public int Exec(string cmd, string args, string cwd) { string errors; string result; int rv = Exec(cmd, args, cwd, out result, out errors); log.WriteLine(2, result); if (errors.Length>0) log.WriteLine(5, errors); return rv; } #region ICmdExec Members public void Start(string cmd, string args, string cwd) { log.WriteLine(1, "Executing: {0} {1}", cmd, args); ProcessStartInfo psi = new ProcessStartInfo(cmd, args); psi.CreateNoWindow = true; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.UseShellExecute = false; psi.WorkingDirectory = cwd; // Needed for P4CONFIG to work Process.Start(psi); } #endregion } }