I want to create exe file in that I want to pass parameters in C#.net
for eg: myexe.exe "hello"
pls help
I want to create exe file in that I want to pass parameters in C#.net
for eg: myexe.exe "hello"
pls help
Use command arguments for this :
static void Main(string[] args)
{
if (args.Length > 0)
{
Console.WriteLine("You Provided " + args[0]);
}
}
and now you can execute myexe.exe "hello" and it will print
You Provided hello
to make your app receive parameters
static void Main(string [] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// the args is the arguments you want to pass to this application
Application.Run();
}
to call it from a c# application
static void CallProcess(string[] args)
{
// create a new process
Process pro= new Process();
pro.StartInfo.FileName = "exe path";
pro.StartInfo.Arguments = args;
pro.Start();
}
Main()
method has arguments which will hold your "hello":
static int Main(string[] args)
{
System.Console.WriteLine(args[0]); //this will output "hello", when you call yourApp.exe "hello"
}