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 工具,但文件名或命令有问题...请您查看屏幕截图并说出问题所在? 在此处输入图像描述

4

4 回答 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 file1 file2

于 2012-11-16T11:24:35.630 回答
2
var args = String.Format("{0} {1}", fileName, fileName2);
Process.Start(kdiffPath, args);
于 2012-11-16T11:26:15.857 回答
0

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

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

除非您尝试做其他事情,在这种情况下您需要提供更多详细信息。

于 2012-11-16T11:22:41.840 回答
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();
于 2012-11-16T11:25:04.160 回答