Click here to Skip to main content
15,444,490 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to access the commandline arguments from WPF application.Heere is the code i followed

C#
try
      {
          foreach (string arg in Environment.GetCommandLineArgs())
          {
              if (arg == "–Auto_BlueGrass")
              {
                  for (int i = 0; i < 2; i++)
                  {
                      if (i == 0)
                      {

                      }
                  }
          }
     }


The above code i wrote to access the command line arguments . when i run the exe from the cmd and pass the -Auto_BlueGrass switch by typing it then the if loop is not executing i.e., the cursor is not coming to for loop.

If i pass the switch by pasting -Auto_BlueGrass instead of typing in the cmd after the exe then it is executing the for loop.

Why this is happening.
Please let me know if iam writing anythingwrong.

thanks in advance
Posted
Comments
Michael dg 16-Feb-12 8:18am    
Basically your code is working. Try to read this article there are some tips. http://developingfor.net/2009/01/12/accessing-command-line-arguments-in-wpf/
infobeena 16-Feb-12 8:31am    
ok
infobeena 16-Feb-12 8:33am    
k
infobeena 16-Feb-12 8:32am    
this code working fine.

try replacing the if clause:

C#
if (arg.Equals("-Auto_BlueGrass", StringComparison.InvariantCultureIgnoreCase))
 
Share this answer
 
Your code works fine on my system. Are you sure you are typing the argument correctly.
BTW Why don't you add a 'poor man debug info' like
C#
Console.WriteLine("arg {0}", arg);

to your code?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900