Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug program that pass argument to Main? [duplicate]

Tags:

c#

console

I am writing a Console application that pass a string array of arguments to the Main. Using the F5 to debug would throw me an exception because I have not pass the arguments.

The way I debug/test the code where I can pass arguments is to build the solution and then run the .exe on the command prompt, but it's very inconvenient.

Is there a way to pass arguments to debug?

like image 612
KMC Avatar asked Feb 28 '12 08:02

KMC


People also ask

How do you pass arguments in Visual Studio debugging?

To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line. They will be passed to the program via the argv array.

How do you pass args with gdb?

You can optionally have gdb pass any arguments after the executable file to the inferior using --args . This option stops option processing. This will cause gdb to debug gcc , and to set gcc 's command-line arguments (see Arguments) to ` -O2 -c foo. c '.

How do I debug command prompt in Visual Studio?

In Visual Studio 2010, right click the project, choose Properties, click the configuring properties section on the left pane, then click Debugging, then on the right pane there is a box for command arguments. In that enter the command line arguments. You are good to go. Now debug and see the result.

How do you pass command line arguments to AC program that is being debugged using gdb?

Passing arguments to the program being debugged. The --args option must be immediately followed by the command invoking the program you wish to debug. That command should consist of the program name and then its arguments, just as they would appear if you were starting that program without GDB.


4 Answers

From within Visual Studio? Absolutely - go to the project's property designer, select the Debug page and you can set the command line arguments, as well as the working directory. See MSDN for more information.

like image 65
Jon Skeet Avatar answered Oct 22 '22 06:10

Jon Skeet


In Visual Studio right-click on the project name in Solution Explorer. Select Properties from the list. Go to the Debug tab. You can put your parameters in Command Line Arguments textbox.

like image 33
Adam Pope Avatar answered Oct 22 '22 07:10

Adam Pope


This page has documentation on C# debugging. Basically, there is a "command line arguments" option in the project's property pages.

like image 33
Ken Wayne VanderLinde Avatar answered Oct 22 '22 06:10

Ken Wayne VanderLinde


You should be able to enter command line arguments in the Project Settings dialog.

There's some info here: http://msdn.microsoft.com/en-us/library/2kf0yb05.aspx

like image 29
Jon Egerton Avatar answered Oct 22 '22 07:10

Jon Egerton