I currently have an application with a GUI.
Would it be possible to use this same application from the commandline (without GUI and with using parameters).
Or do I have to create a separate .exe (and application) for the commandline tool?
I currently have an application with a GUI.
Would it be possible to use this same application from the commandline (without GUI and with using parameters).
Or do I have to create a separate .exe (and application) for the commandline tool?
Not enough points to comment. I wanted to add to the accepted solution that the [DllImport("kernel32.dll")] is not needed to write to the console when using mingw to call the program, it seems this is a windows/dos issue.
I think it is possible, just set your subsystem to "console", you will see a console window as well as the GUI window.
But in order to accept commands from the console window, I guess you will have to create an extra thread to do it.
Main
function accepts command line parameters.Here's a short example:
If your app isn't already structured to cleanly do silent processing (if all your logic is jammed into your WinForm code), you can hack silent processing in ala CharithJ's answer.
EDIT by OP Sorry to hijack your answer Merlyn. Just want all the info here for others.
To be able to write to console in a WinForms app just do the following:
You may need to structure your Application as a Console Application, identify what you do on "Actions" - like clicking of the button - into separate class, include a form that can be shown if there were no command line arguments supplied, and handle events by routing them to the common methods in your "Action" class.
In your program.cs class keep the Main method as it is but add
string[] Args
to the main form. For example...In mainform.cs constructor