how to pass args to console app?

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

Hello,

how do you pass args to a console app?

class TestApp
{
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
TestApp testApp = new TestApp();
testApp.Start(args);
}

public void Start(string[] args)
{
...
)
}

Thanks,
Ron
 
In VS.NET, open properties dialog for the project and select the debugging
tree item. Enter the parameters in the Command Line Arguments setting.

At the command prompt, the parameters follow the name of the add name.
 
hi Ron! :O)
how do you pass args to a console app?

//***
using System;

namespace ConsoleArgsProject
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
if (args.Length > 0)
Console.WriteLine(args[0]);

Console.WriteLine();
Console.WriteLine("Press Enter to quit...");
Console.ReadLine();
}
}
}
//***

now if you actually want to test it (i don't have the exact menu/item names)
:

- open the Project Properties (from the Project menu, last item in the list)
- go in the configuration properties
- select debugging
- you can add a test arguments line in there
- start your app
 
Ron said:
how do you pass args to a console app?

class TestApp
{
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
TestApp testApp = new TestApp();
testApp.Start(args);
}

public void Start(string[] args)
{
...
)
}

Not really sure what you mean here - are you talking about creating a
new process with Process.Start? If so, you can use
ProcessStartInfo.Arguments, although you'll need to concatenate all the
arguments together and quote any that have spaces in.
 
Thanks all for your replies. The solution was to enter
the args in the Debug Command Line in the Project
Properties. That worked! Thanks all for letting me know
about this.

Ron
 
Back
Top