I have a Winform application which can be run in GUI mode as well as in command prompt.
In the command prompt, I basically call appropriate button depending upon the given command line argument. For example: "C:/> MyTool param1" will call Button1_ClickEventHanlder() internally
In this Button1_ClickEventHandler() method, I set Environment.ExitCode to some value depending upon some conditions.
My question is how to get Environment.ExitCode value from the Command line in a winform app?
I tried echo %errorcode% after running my app from command prompt but no luck, it's always giving 0. Even I tried "start /wait MyTool param1" too but it's not giving proper ExitCode value what it's supposed to give as per code logic.
Please help me to resolve this issue.
Loading
Tulika KumarPosted Oct 30, 2013, 4:03 PM
Actually I figured it out why "start /wait MyTool param1" was giving random value (non -zero)
This is because a DLL what I was using in my code that was thorwing an UNHANDLED exception (not regular exception). This I could figured it out when I build my Win App as a Console App using your suggestion.
So, final conclusion I got for my Winform app.
Thanks again for your kind suggestions.
VulpesPosted Oct 29, 2013, 7:25 PM
You can certainly do this even from VS by setting the output type under the Build tab of the project's properties to Console application. It should still work fine except that there will now be a console attached.
Otherwise, I think the only thing you can do is to write the exitcode to a text file and then 'type' that from the command line.