I want to run a console application (eg app.exe) from a windows form load event. I'v tried System.Diagnostics.Process.Start(), But after it opens app.exe, it closes it immidiately.
Is there any way that I can run app.exe and leave it open?
I want to run a console application (eg app.exe) from a windows form load event. I'v tried System.Diagnostics.Process.Start(), But after it opens app.exe, it closes it immidiately.
Is there any way that I can run app.exe and leave it open?
If you have control over app.exe, you should be aware of how it functions so I will assume that you do not have control over it's inner workings. In that case, you can try passing a help flag which may or may not give you more info on how to call app.exe. Try something like this:
Create a new text file, name it app.bat and put this in there:
Now have your form point to that bat file.
If you can change the code of app.exe, just add
Console.In.Read()
to make it wait for a key press.app.exe can end with
Console.ReadLine()
assuming it too is a C# application where you control the source code.Try doing this:
I think this will get you the behavior you are trying for. Assuming you weren't just trying to see the output in the command window. If you just want to see the output, you have several versions of that answer already. This is just how you can run your app and keep the console open.
Hope this helps. Good luck.
If app.exe does nothing, or finishes its work quickly (i.e. simply prints "Hello World" and returns), it will behave the way you just explained. If you want app.exe to stay open after its work is done, put some sort of completion message followed by
Console.ReadKey();
in the console application.