Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run console application from other console app

I have a C# console application (A). I want to execute other console app (B) from within app A (in synchronous manner) in such way that B uses the same command window. When B exists, A should be able to read B's exit code.

How to do that? I need only this little tip on how to run this other app in same cmd window.

like image 203
Dawid Ohia Avatar asked Mar 02 '10 19:03

Dawid Ohia


People also ask

How do I run a console application?

Run the appPress Ctrl + F5 to run the program without debugging. A console window opens with the text "Hello World!" printed on the screen. Press any key to close the console window.

How do I call a console application from web API?

Step 1: First, create a console application in Visual Studio 2013 for Desktop. Step 2: Open NuGet Package Manager console from TOOLS -> NuGet Package Manager -> Package Manager Console and execute following command.


1 Answers

You can use Process.Start to start the other console application.

You will need to construct the process with ProcessStartInfo.RedirectOutput set to true and UseShellExecute set to false in order to be able to utilize the output yourself.

You can then read the output using StandardOutput.ReadToEnd on the process.

like image 80
Oded Avatar answered Oct 13 '22 13:10

Oded