Skip to main content
 首页 » 编程设计

c#之在命令提示符下使用 c# 为 wpf 应用程序执行命令

2024年02月23日14jillzhang

我目前正在构建一个 WPF 应用程序。我希望能够选择一个二进制文件,使用命令提示符命令行参数将其解码为 .csv 文件,在我的应用程序中编辑它的值,然后使用解码工具将其解码回二进制文件。我唯一的部分卡在命令提示符中输入我的命令行参数。我用谷歌搜索了一些东西,但我只能找到有关如何从代码打开命令提示符而不是如何执行命令的信息。

如有任何帮助,我们将不胜感激。 谢谢!

请您参考如下方法:

checkout Process 类,它是 .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); 
        } 
    } 
    } 
} 

示例的一些链接: