-1

I have created a C# command line application that creates a few reports automatically for my client. However, even though they use 95% of the same code I would like to split them in to different processes. I am using Windows task scheduler to run them. How do I set up the C# application to accept Command line parameters upon runtime?

I cannot find any explanation of this on the internet.

2
  • 7
    "I cannot find any explanation of this on the internet. " -- then you must not have tried hard enough. This is basic basic stuff. Very well documented. Check MSDN. Commented Mar 1, 2017 at 15:34
  • 2
    Other than static void Main(string[] args)? Commented Mar 1, 2017 at 15:35

2 Answers 2

3

All command line parameters are passed to your application through string[] args parameter.
The code below shows an example:

using System.Linq;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Contains("/REPORT1"))
            {
                /* Do something */
            }
            else if (args.Contains("/REPORT2"))
            {
                /* Do something */
            }
        }
    }
}

Then, in command prompt just use:

C:\MyApp\MyApp.exe /REPORT1
Sign up to request clarification or add additional context in comments.

Comments

1

MSDN

The below snippet will print the number of parameters passed from the command line... string[] args contains the parameter values...

class TestClass
{
    static void Main(string[] args)
    {
        // Display the number of command line arguments:
        System.Console.WriteLine(args.Length);
    }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.