Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dual purposing an application to run as winform or command line utillity

Sorry my title is rather vague but I don't know how to concisely label what I want to do.

I have a winform application which were trying to dual-purpose so it can also be run as a command line utility by our automation system. In the programs Main() I am conditionally executed the desired code. The only problem is that (despite logging to Console) a command window is not being launched. What do I need to do to make the application launch a command window and direct stdout to that?

Below is my main (HeadlessExecution is correctly being executed):

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        if (!ValidateCommandLineArgs())
            Application.Run(new TestResultForm());
        else
        {
            HeadlessExecution();
        }
    }
like image 459
evanmcdonnal Avatar asked Dec 04 '25 15:12

evanmcdonnal


1 Answers

Extract all the logic into a different, class assembly.

Reference this assembly in a winforms and in a console application. Voila.

like image 96
Oded Avatar answered Dec 06 '25 05:12

Oded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!