I am using Beyond Compare 3 in my win forms application to do a comparison in two output folders (ProdOutput and SITOutput). I am using the below lines of code for doing the comparison
public static void LaunchViewer(string filepath1, string filepath2)
{
string arguments = String.Format("\"{0}\" \"{1}\"", filepath1, filepath2);
ProcessStartInfo psi = new ProcessStartInfo(ApplicationPath, arguments);
using (Process p = Process.Start(psi))
{
ComparsionResult = CompareFiles(filepath1, filepath2, BeyondCompareRules.EverythingElse);
}
}
public static ComparisonResult CompareFiles(string filepath1, string filepath2, string ruleName)
{
ComparisonResult result = ComparisonResult.None;
string arguments = String.Format("/quickcompare /rules=\"{0}\" \"{1}\" \"{2}\"", ruleName, filepath1, filepath2);
ProcessStartInfo psi = new ProcessStartInfo(ApplicationPath, arguments);
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
using (Process p = Process.Start(psi))
{
p.StandardInput.WriteLine("EXIT [ErrorLevel]");
p.WaitForExit();
int exitCode = p.ExitCode;
switch (exitCode)
{
case 0:
result = ComparisonResult.Match;
break;
case 1:
result = ComparisonResult.Similar;
break;
case 2:
result = ComparisonResult.DoNotMatch;
break;
case 3:
result = ComparisonResult.ComparisonError;
break;
default :
result = ComparisonResult.DoNotMatch;
break;
}
}
return result;
}
Beyond compare rules are below
public sealed class BeyondCompareRules
{
private BeyondCompareRules()
{
}
/// <summary>
/// A comparison rule set for C/C++/C# source files
/// </summary>
public const string CLanguageSource = "C/C++/C# Source";
public const string Cobol = "COBOL";
public const string CommaSeparatedValues = "Comma Separated Values";
public const string DelphiSource = "Delphi Source";
public const string DelphiForms = "Delphi Forms";
public const string GeneralText = "General Text";
public const string Html = "HTML";
public const string Java = "JAVA";
public const string Python = "Python";
public const string RegistryDump = "Registry Dump";
public const string Utf8Text = "UTF8 Text";
public const string VisualBasic = "Visual Basic";
public const string Xml = "XML";
/// <summary>
/// The default set of comparison rules
/// </summary>
public const string EverythingElse = "Everything Else";
}
and comparisonresult is an enum as below
public enum ComparisonResult
{
/// <summary>
/// Indicates a null or uninitialized value
/// </summary>
None = 0,
/// <summary>
/// The Quick Compare returned a Positive Match
/// </summary>
Match = 1,
/// <summary>
/// The Quick Compare detected small differences
/// </summary>
Similar = 2,
/// <summary>
/// The Quick Compare detected significant differences
/// </summary>
DoNotMatch = 3,
/// <summary>
/// The Quick Compare utility returned an error/unknown result
/// </summary>
ComparisonError = 4
}
What I need is to suppress launching the beyond compare screen when doing the comparison but the comparison should happen and it should return result. Now with my above code I am able to do the comparison and also able to view the differences which I don't want to do.
I guess there is some thing which I can do with passing arguments but not sure what is it and how and where should I put it.
Any help highly appreciated.
After several trials with different ways to achieve the functionality, finally a small piece of code did resolved the issue.
There is a command line switches available for beyond compare application which needs to be passed when we want to suppress the interactions. It is called "/silent".
I have passed along with these lines in CompareFiles method
public static ComparisonResult CompareFiles(string filepath1, string filepath2, string ruleName)
ComparisonResult result = ComparisonResult.None;
string arguments = String.Format("/quickcompare /rules=\"{0}\" \"{1}\" \"{2}\" /silent", ruleName, filepath1, filepath2);
All the above posted code in my question is working fine and can be used by any one who wants to suppress the interactions.