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

C# 如何从控制台应用程序启动kdiff?,c#,C#,更新 我想从控制台应用程序调用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:\v

更新

我想从控制台应用程序调用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工具,但文件名或命令有问题。。。你能看一下屏幕截图并说出什么问题吗?

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

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

除非您尝试执行其他操作,否则您需要提供更多详细信息。

您需要使用
Process.Start()


文档中描述的参数:
kdiff3 file1 file2

很酷,但是如何打开两个文件的比较?我想这应该是如何使用一组参数(文件名)运行kdiff3的方法,它应该打开两个文件的比较对话框(不仅仅是kdiff3工具)。这就是为什么我添加了,我认为应该注意文件名中的空格。
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();
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();
var args = String.Format("{0} {1}", fileName, fileName2);
Process.Start(kdiffPath, args);