我目前正在构建一个 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);
}
}
}
}
示例的一些链接:
- http://support.microsoft.com/kb/305369/en-us
- c# ProcessStartInfo.Start - reading output but with a timeout
- http://www.dotnetperls.com/process-start
- http://weblogs.asp.net/guystarbuck/archive/2008/02/06/invoking-cmd-exe-from-net.aspx
- http://www.jonasjohn.de/snippets/csharp/run-console-app-without-dos-box.htm
- http://dfcowell.net/2011/01/printing-a-pdf-in-c-net-adobe-reader/
关于c# - 在命令提示符下使用 c# 为 wpf 应用程序执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7135432/