2011-08-20 281 views
1

我目前正在構建一個WPF應用程序。我希望能夠選擇二進制文件,使用命令行命令行參數將其解碼爲.csv文件,在我的應用程序中編輯其值,然後使用解碼工具將其解碼爲二進制文件。 'm卡在正在輸入我的命令行參數到命令提示符中。我搜索了一些東西,但我只能找到關於如何從代碼打開命令提示符的信息,而不是如何執行命令。在命令提示符下使用c#爲wpf應用程序執行命令

任何幫助將不勝感激。 謝謝!

+1

有很多受騙者對SO爲:如何在C#中的shell中執行命令? WPF與這個問題沒有任何關係。 –

回答

4

結帳處理類,它是.NET框架的一部分 - 有關更多信息和示例代碼,請參閱its documentation at MSDN

編輯 - 按評論:

即開始7zip的,讀的StdOut

using System; 
using System.Diagnostics; 
using System.IO; 

class Program 
{ 
    static void Main() 
    { 
    ProcessStartInfo start = new ProcessStartInfo(); 
    start.FileName = @"C:\7za.exe"; // Specify exe name. 
    start.UseShellExecute = false; 
    start.RedirectStandardOutput = true; 

    using (Process process = Process.Start(start)) 
    { 
     // Read in all the text from the process with the StreamReader. 
     using (StreamReader reader = process.StandardOutput) 
     { 
     string result = reader.ReadToEnd(); 
     Console.Write(result); 
     } 
    } 
    } 
} 

一些鏈接樣本

示例代碼:

+0

添加一個代碼示例更多upvotes :) –

+1

按要求添加了一個示例和一些鏈接到幾個樣本... – Yahia

相關問題