Benjamin Arancibia
Benjamin Arancibia

Reputation: 47

How to pass parameters from a batch file

I have a batch file that execute my console application. I need to pass a parameters inside the console but I don't know how to pass it and how to add it into the main() The parameters are projectsId

This is what I have into my batch file:

@echo off
start "C:\Users\testUser\Documents\console.exe %2345867162 %4756473622

This is my code from my console application

static void Main(string[] args)
{
    data();
}

string ProjectID = "";

byte[] MyBinFiles = db.GetResponse3(ProjectID);    

System.IO.File.WriteAllBytes(MyBinFiles);

Upvotes: 1

Views: 1802

Answers (2)

sevzas
sevzas

Reputation: 801

As an alternative to using the arguments of the Main method, you can use Environment.GetCommandLineArgs() http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs.aspx

Upvotes: 0

Hamid Pourjam
Hamid Pourjam

Reputation: 20744

The Main method is the entry point of a C# console application or windows application. (Libraries and services do not require a Main method as an entry point.). When the application is started, the Main method is the first method that is invoked.

You can send arguments to the Main method by defining the method in one of the following ways: static int Main(string[] args) static void Main(string[] args)

read this

parameters that are passed to the main method of your program are accessible through args array in Main method. use them the way you want

Upvotes: 1

Related Questions