2012-11-16 82 views
4

已更新...如何從控制檯應用程序啓動kdiff?

我想從控制檯應用程序調用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

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

+0

可以請你再看看我的帖子?我已經更新了它。 – Vytalyi

+0

這就是爲什麼我添加了「,應該照顧文件名中的空格我認爲。 – Lloyd

0

除非你正在嘗試做別的事情,在這種情況下,你需要提供更多的詳細信息,這將會從您的控制檯應用程序

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

運行程序。

+0

很酷,但如何打開的兩個文件的比較? – Vytalyi

+0

你是什麼意思? –

+0

我想這應該是如何與組參數(文件名)運行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(); 
2
var args = String.Format("{0} {1}", fileName, fileName2); 
Process.Start(kdiffPath, args); 
+0

是的,它也工作,謝謝。 – Vytalyi

相關問題