简体   繁体   English

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

[英]Executing a command in the command prompt using c# for a wpf application

I'm currently building a WPF application. 我正在构建一个WPF应用程序。 I want to be able to choose a binary file, decode it using the command prompt command line arguments into a .csv file, edit its value in my application then decode it back to a binary file using a decoding tool.The only part where I'm stuck at is entering my commandline arguments into the command prompt. 我希望能够选择一个二进制文件,使用命令提示符命令行参数将其解码为.csv文件,在我的应用程序中编辑其值,然后使用解码工具将其解码回二进制文件。我唯一的部分我坚持在命令提示符下输入我的命令行参数。 I googled stuff, but I could only find information on how to open the command prompt from code and not how to execute a command. 我搜索了一些内容,但我只能找到有关如何从代码中打开命令提示符而不是如何执行命令的信息。

Any help would be greatly appreciated. 任何帮助将不胜感激。 thanks! 谢谢!

checkout Process class, it is part of the .NET framework - for more information and some sample code see its documentation at MSDN . checkout Process类,它是.NET框架的一部分 - 有关更多信息和一些示例代码,请参阅MSDN上的文档

EDIT - as per comment: 编辑 - 根据评论:

sample code that start 7zip and reads StdOut 示例代码,启动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);
        }
    }
    }
}

some links to samples: 一些样本链接:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM