c# how to programmatically execute exe and wait till it finish execution

Hi Guys,

So in my process of developing a util that utilizes “A well known javascript compressor” to compress javascript files. I came across where I had a need to run Java.exe from my c# application.

You must be aware of Process class under System.Diagnostics package.

We will be utilizing Process class to execute java from command line and keep the window hidden and also stop the flow of program until called EXE finishes execution


If this solution can be improved please leave you comments but I guess its pretty much standard using c# libraries so can’t go wrong with that

This is how I did it finally.

[geshi lang=”csharp” nums=”1″ target=”_self” ]


Important piece of information in above code is start.CreateNoWindow = true, by default this value is false, When you set it to true, then  you are directing your program that keep the called program hidden.

When you call WaitForExit on  the process it sets the period of time to wait for the associated process to exit, and blocks the current thread of execution until the time has elapsed or the process has exited.

Read more here about WaitForExit 


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.