1

I'm currently building a WPF application. 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!

1
  • 1
    There are plenty of dupes on SO for: How do I execute a command on the shell in C#? WPF doesn't have anything to do with this question. Commented Aug 21, 2011 at 3:23

1 Answer 1

5

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:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.