Tolga E
Tolga E

Reputation: 12678

How to include an executable with my project and call it in .NET

I have an .exe file, which is just a command line tool for a certain encryption. I have a .NET project and I want to include this with my program and be able to make command line calls to this exe and gets its response...

How can I include this .exe?

Upvotes: 1

Views: 382

Answers (2)

Parimal Raj
Parimal Raj

Reputation: 20575

This can be quite easily achieved using the ProcessStartInfo.RedirectStandardOutput property. A full sample is contained in the linked MSDN documentation; the only caveat is that you may have to redirect the standard error stream as well to see all output of your application.

Process process = new Process();
process.StartInfo.FileName = "your_application.exe";
process.StartInfo.Arguments = "argument1 argument2 argument2 ...";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();    

Console.WriteLine(process.StandardOutput.ReadToEnd());

process.WaitForExit();

Upvotes: 3

whastupduck
whastupduck

Reputation: 1166

You can make a class library (DLL) that calls the executable's functions. Basically, you reference the created DLL in your other project. It acts as a middle man between your application and the other executable.

See here

Include the executable project in your class library project so you can call the encryption function.

Upvotes: 1

Related Questions