如何从控制台应用程序启动kdiff?

4

更新...

我想从控制台应用程序中调用kdiff。因此,我正在构建两个文件,并希望在执行程序结束时比较它们:

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

它运行了kdiff3工具,但文件名或命令出了些问题...你能看一下截图并告诉我哪里有问题吗? enter image description here

4个回答

4
您需要使用 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));

根据文档描述,参数为:kdiff3 文件1 文件2


这就是为什么我加了“,应该注意文件名中的空格,我想。 - Lloyd

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

0

这将从您的控制台应用程序运行该程序

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

除非你想做其他事情,否则你需要提供更多细节。


酷,但如何打开两个文件的比较? - Vytalyi
我想这应该是如何使用一组参数(文件名)运行kdiff3,并打开两个文件对比对话框的方法(而不仅仅是kdiff3工具)。 - Vytalyi

0
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();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接