I need to create a console application that can take multiple different launch arguments (which can be added using the batch file). I so far tried this, but it seems like I don't understand it correctly.
Code:
static void Main(string[] args)
{
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.Arguments = LaunchArguments.Operation_AddLocale;
processStartInfo.Arguments = LaunchArguments.Operation_CreateTextFile;
processStartInfo.UseShellExecute = false;
if (processStartInfo.Arguments == LaunchArguments.Operation_CreateTextFile)
{
Console.WriteLine("Creating a text file.");
File.Create("file.txt");
Console.Write("Done!");
}
if (processStartInfo.Arguments == LaunchArguments.Operation_AddLocale)
{
if (Directory.Exists("locale"))
{
try
{
File.Create("locale.txt");
}
catch (Exception ex)
{
Console.WriteLine("An error occured: ");
Console.Write(ex.ToString());
Console.Write(ex.Message.ToString());
Console.ReadLine();
}
}
else
{
Console.WriteLine("Incorrect Input, quitting");
Console.WriteLine("This application only accepts arguments of type '-CreateTextFile; -AddLocale'");
Console.Beep();
Console.ReadLine();
}
}
I made a constant string 'Operation_AddLocale' and 'Operation_CreateTextFile'.
by batch file:
@echo off
start SW_project_generator.exe -AddLocale
This all should do that if I launch the application via this batch file, it will do the operations that are in the 'if (processStartInfo.Arguments == LaunchArguments.Operation_AddLocale)' and if the batch file would add the '-CreateTextFile' argument, it will go to the 'if (processStartInfo.Arguments == LaunchArguments.Operation_CreateTextFile)'.
However, when I launch this app via my batch file, it will always just use the first argument (which is the '-CreateTextFile') and creates a text file and then goes to the else option.
Application's Output:
Creating a text file. Done!Incorrect Input, quitting This application only accepts arguments of type '-CreateTextFile; -AddLocale;'
Alright so, my question is, how to make this working, that if I create a batch file give it a argument of type '-AddLocale' it will just go to the 'AddLocale' operations and if I give it something else that is defined in the app, like the 'CreateTextFile', it'll go to it's 'if' statement. And finnaly, if the launch argument will be equal to nothing or wrong one, it'll show the quitting message.
Thanks everyone for help.