Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to execute my console application by a batch file..
actually how to do that? and if i want to pass parameter from batch file to this exe
is it do able?
my console app header like below:-

C#
static void Main(string[] args)
{
  string ls_FileExt = "", ls_FileName = "";
  DateTime ldt_CurrDateTime = System.DateTime.Now;
  string[] files = Directory.GetFiles("C:\\A");

//--
}


By CS
Posted

Use a Process object.
How to launch Windows applications (Notepad) / Call Batch files from a C#/.NET console application.[^] is a good article that should help you out.
 
Share this answer
 
Comments
Member 2321293 24-Aug-11 3:27am    
thank you
Why not use the args parameter of your Main method? That is exactly what it is there for...



"able to show me some example, becourse i am not good in console app and batch file also"

Batch file:
myAppName ParameterText MoreParameters

Your app:
C#
static void Main(string[] args)
   {
   foreach (string arg in args)
      {
      Console.WriteLine(arg);
      }
   }

Output:
ParameterText
MoreParameters
 
Share this answer
 
v2
Comments
Member 2321293 23-Aug-11 4:29am    
able to show me some example, becourse i am not good in console app and batch file also
OriginalGriff 23-Aug-11 4:36am    
Answer updated
Member 2321293 23-Aug-11 4:51am    
hi, thanks for the fast respone..
i try to write something like below at my batch file
START "C:\myFiles\FileControl\FileControl\bin\Debug\FileControl" "C:\\A" "C:\\AA"
pause
but it seem can't perform the function..
is my batch file write something wrong?
OriginalGriff 23-Aug-11 5:01am    
Don't use the START command: http://www.robvanderwoude.com/start.php
You don't need it unless you are trying to start the app in a different session - with the pause there, you definitely don't need that.
And you can probably dump the double quotes round the parameters, and the spare '\' characters as well: check with Console.WriteLine

Just get rid of the START - will probably cure it.

[edit]Spelling, last sentence added - OriginalGriff[/edit]
Member 2321293 23-Aug-11 5:22am    
hi i changed the coding to
"C:\myFiles\FileControl\FileControl\bin\Debug\FileControl.exe" "%C:\\A" "%C:\\AA"
But i get the result for
Console.WriteLine(args[0].toString()); return: \\A
Console.WriteLine(args[1].toString()); return: \\AA
how to make it return "C:\\A" or "C:\\AA" ? the "C:" are missing... :S

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