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

标签 c# wpf command-line command-line-arguments command-prompt

我目前正在构建一个 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);
        }
    }
    }
}

示例的一些链接:

关于c# - 在命令提示符下使用 c# 为 wpf 应用程序执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7135432/

相关文章:

c# - WPF TreeView 泄漏所选项目

c# - ASP :listview add a <div class ="clear"> after every 3 items

c# - 关于 C# 和 VB.net 异同的面试问题

WPF - 从组标题样式中绑定(bind)到当前项目

linux - 为什么使用-rf?

c# - View 中的 ASP.Net MVC 多重继承

c# - 设置 IntervalBarSeries 的标签 (oxyplot)

c# - 在WPF中使用MVVM将筛选器文本框添加到组合框

linux - 如何区分 $1 作为 shell 变量和 $1 作为 awk 变量?

python - 如何在Go中将文本复制到剪贴板或从剪贴板复制文本?