If you are creating a Windows application, than unfortunally Console.WriteLn does not do anything. While in the debugger you see the output in the output window, but if started from the commandline it doesn't. The Windows app does not have a hook to the commandline.
Of course if you made a console application it will work.
Like Marcel already wrote - if you created Windows app, try outputing your parameters some other way - maybe by showing a message box for each parameter:
for(int i = 0; i < args.Length; i++) { MessageBox.Show(string.Format("Param {0} = {1}", i, args[ i ])); }
Could you be more specific with what didn't work The Main method should be application's default entry point which gets called every time the application is started.
[The default Main method is located in the static Program class in Program.cs].
How can I access parameters given from the Command Line?
suranga_d
hi.,
It is work when I do like this:
I went to the start menu - run and typed
C:\MyProgram Folder\AppPath.exe param
The output is
Param 0 = param
I don't know why yours not work. May be you didn't specify the filepath in the Run.
my code is here.
static
void Main(string[] args){
for(int i = 0; i < args.Length; i++){
}
Console.Read();
}
:)
soemoe
newjdevil
If you are creating a Windows application, than unfortunally Console.WriteLn does not do anything. While in the debugger you see the output in the output window, but if started from the commandline it doesn't. The Windows app does not have a hook to the commandline.
Of course if you made a console application it will work.
Francis Shanahan
Like Marcel already wrote - if you created Windows app, try outputing your parameters some other way - maybe by showing a message box for each parameter:
for(int i = 0; i < args.Length; i++)
{
MessageBox.Show(string.Format("Param {0} = {1}", i, args[ i ]));
}
Andrej
japt
Could you be more specific with what didn't work The Main method should be application's default entry point which gets called every time the application is started.
[The default Main method is located in the static Program class in Program.cs].
Andrej
Jesse Towner
"AppPath.exe" "ParamHere"
The program code look somthing like this
for(iny i = 0; i < args.Length; i++)
{
Console.WriteLine("Param {0} = {1}", i, args[ i ]);
}
The program wrote nothing...
Any Ideas
Thanx
Mike
AnilK110285
TIA
Mike
Keith Henkel
Hi,
try the following:
[
STAThread]static void Main(string[] args)
{
if (args.Length > 0)
{
string firstParameter = args[0];
}
}
Andrej