/// <summary> /// Execute a remote command, capturing the output text /// </summary> /// <param name="Command">Command to be executed</param> /// <param name="Output">Receives the output text</param> /// <returns></returns> protected int ExecuteAndCaptureOutput(string Command, out StringBuilder Output) { StringBuilder FullCommand = new StringBuilder(); foreach (string CommonSshArgument in CommonSshArguments) { FullCommand.AppendFormat("{0} ", CommonSshArgument); } FullCommand.Append(Command.Replace("\"", "\\\"")); using (Process SSHProcess = new Process()) { Output = new StringBuilder(); StringBuilder OutputLocal = Output; DataReceivedEventHandler OutputHandler = (E, Args) => { if (Args.Data != null) { OutputLocal.Append(Args.Data); } }; SSHProcess.StartInfo.FileName = SshExe.FullName; SSHProcess.StartInfo.WorkingDirectory = SshExe.Directory.FullName; SSHProcess.StartInfo.Arguments = FullCommand.ToString(); SSHProcess.OutputDataReceived += OutputHandler; SSHProcess.ErrorDataReceived += OutputHandler; Log.TraceLog("[SSH] {0} {1}", Utils.MakePathSafeToUseWithCommandLine(SSHProcess.StartInfo.FileName), SSHProcess.StartInfo.Arguments); return(Utils.RunLocalProcess(SSHProcess)); } }
/// <summary> /// Execute Rsync /// </summary> /// <param name="Arguments">Arguments for the Rsync command</param> /// <returns>Exit code from Rsync</returns> private int Rsync(string Arguments) { using (Process RsyncProcess = new Process()) { RsyncProcess.StartInfo.FileName = RsyncExe.FullName; RsyncProcess.StartInfo.Arguments = Arguments; RsyncProcess.StartInfo.WorkingDirectory = SshExe.Directory.FullName; RsyncProcess.OutputDataReceived += RsyncOutput; RsyncProcess.ErrorDataReceived += RsyncOutput; Log.TraceLog("[Rsync] {0} {1}", Utils.MakePathSafeToUseWithCommandLine(RsyncProcess.StartInfo.FileName), RsyncProcess.StartInfo.Arguments); return(Utils.RunLocalProcess(RsyncProcess)); } }
/// <summary> /// Execute a remote command, capturing the output text /// </summary> /// <param name="WorkingDirectory">The remote working directory</param> /// <param name="Command">Command to be executed</param> /// <returns></returns> protected int Execute(string WorkingDirectory, string Command) { string FullCommand = String.Format("cd {0} && {1}", EscapeShellArgument(WorkingDirectory), Command); using (Process SSHProcess = new Process()) { DataReceivedEventHandler OutputHandler = (E, Args) => { SshOutput(Args); }; SSHProcess.StartInfo.FileName = SshExe.FullName; SSHProcess.StartInfo.WorkingDirectory = SshExe.Directory.FullName; SSHProcess.StartInfo.Arguments = String.Format("{0} {1}", String.Join(" ", CommonSshArguments), FullCommand.Replace("\"", "\\\"")); SSHProcess.OutputDataReceived += OutputHandler; SSHProcess.ErrorDataReceived += OutputHandler; Log.TraceLog("[SSH] {0} {1}", Utils.MakePathSafeToUseWithCommandLine(SSHProcess.StartInfo.FileName), SSHProcess.StartInfo.Arguments); return(Utils.RunLocalProcess(SSHProcess)); } }
/// <summary> /// Format this object for the debugger /// </summary> /// <returns>String representation of this target descriptor</returns> public override string ToString() { StringBuilder Result = new StringBuilder(); Result.AppendFormat("{0} {1} {2}", Name, Platform, Configuration); if (!String.IsNullOrEmpty(Architecture)) { Result.AppendFormat(" -Architecture={0}", Architecture); } if (ProjectFile != null) { Result.AppendFormat(" -Project={0}", Utils.MakePathSafeToUseWithCommandLine(ProjectFile)); } if (AdditionalArguments != null && AdditionalArguments.Count > 0) { Result.AppendFormat(" {0}", AdditionalArguments); } return(Result.ToString()); }