开发者

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

I'm currently building a WPF applic开发者_运维问答ation. 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. 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.

EDIT - as per comment:

sample code that start 7zip and reads 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:

  • 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/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜