How to run kdiff from a console application?

UPDATED ...

I want to call kdiff from the Console application. Therefore, I create two files and want to compare them at the end of my program:

string diffCmd = string.Format("{0} {1}", Logging.FileNames[0], Logging.FileNames[1]); // diffCmd = D:\vdenisenko\DbHelper\DbHelper\bin\Debug\Reports\16_Nov 06_30_46_DiscussionThreads_ORIGIN.txt D:\vdenisenko\DbHelper\DbHelper\bin\Debug\Reports\16_Nov 06_30_46_DiscussionThreads_ORIGIN.txt System.Diagnostics.Process.Start(@"C:\Program Files (x86)\KDiff3\kdiff3.exe", diffCmd); //specification is here http://kdiff3.sourceforge.net/doc/documentation.html 

It launches the kdiff3 tool, but something is wrong with the file names or the command ... Could you look at the screenshot and say what is wrong? enter image description here

+4
source share
4 answers

You need to use Process.Start() :

 string kdiffPath = @"c:\Program Files\Kdiff3.exe"; // here is full path to kdiff utility string fileName = @"d:\file1.txt"; string fileName2 = @"d:\file2.txt"; Process.Start(kdiffPath,String.Format("\"{0}\" \"{1}\"",fileName,fileName2)); 

Arguments described in the docs: kdiff3 file1 file2

+4
source
 var args = String.Format("{0} {1}", fileName, fileName2); Process.Start(kdiffPath, args); 
+2
source

This will launch the program from your console application.

 Process p = new Process(); p.StartInfo.FileName = kdiffPath; p.StartInfo.Arguments = "\"" + fileName + "\" \"" + fileName2 + "\""; p.Start(); 

If you are not trying to do something else, then you need to provide more detailed information.

0
source
 string kdiffPath = @"c:\Program Files\Kdiff3.exe"; // here is full path to kdiff utility string fileName = @"d:\file1.txt"; string fileName2 = @"d:\file2.txt"; ProcessStartInfo psi = new ProcessStartInfo(kdiffPath); psi.RedirectStandardOutput = true; psi.WindowStyle = ProcessWindowStyle.Hidden; psi.UseShellExecute = false; psi.Arguments = fileName + " " + fileName2; Process app = Process.Start(psi); StreamReader reader = app.StandardOutput; //get reponse from console app in your app do { string line = reader.ReadLine(); } while(!reader.EndOfStream); app.WaitForExit(); 
0
source

Source: https://habr.com/ru/post/1446434/


All Articles