0

I am automating the file compare feature using vsDiffMerge.exe to compare the file using c#.net code that works fine but I need output information from vsDiffMerge.exe to c#.net variable when files are identical, I am using following code to compare the two files using c#.net code and vsDiffMerge.exe from following Visual Studio location C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\vsDiffMerge.exe

    private void CompareFile()
    {
        bool isFileIdentical=false;
        string exe = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\vsDiffMerge.exe";

        string orignalSourceFile = _lstFiles[_selectedRowIndex - 1].SourceFilePath;
        string orignalTargetFile = _lstFiles[_selectedRowIndex - 1].TargetFilePath;

        string command = string.Format(@"""{0}"" ""{1}"" ""Source: {2}"" ""Target : {3}""{4}", sourceFile, targetFile,
                                                                                 orignalSourceFile,
                                                                               orignalTargetFile,
                                                                                chkOnlyOne.Checked ? "" : " /t");

        var attr = File.GetAttributes(sourceFile);
        File.SetAttributes(sourceFile, attr & ~FileAttributes.ReadOnly);

        var attr2 = File.GetAttributes(targetFile);
        File.SetAttributes(targetFile, attr2 & ~FileAttributes.ReadOnly);

        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.CreateNoWindow = false;
        startInfo.UseShellExecute = false;
        startInfo.RedirectStandardOutput = true; 
        startInfo.FileName = exe;
        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
        startInfo.Arguments = command;
        try
        {

            using (Process exeProcess = Process.Start(startInfo))
            {
                //string output = exeProcess.StandardOutput.ReadToEnd();
                //isFileIdentical = exeProcess. ?
                // I need output from exeProcess if both the files are identical 
                exeProcess.WaitForExit();
            }
        }
        catch (Exception ex)
        {
            string e = ex.Message;
        }

    }
Neeraj Kumar Gupta
  • 2,157
  • 7
  • 30
  • 58
  • maybe this helps you http://stackoverflow.com/questions/206323/how-to-execute-command-line-in-c-get-std-out-results – Van De Wack Mar 22 '17 at 14:27
  • thanks @VanDeWack, I already used this "string output = exeProcess.StandardOutput.ReadToEnd();" but it always returns empty , some how I want to get information when file are identical. – Neeraj Kumar Gupta Mar 22 '17 at 14:50

0 Answers0