619

I'm developing a C++ command-line application in Visual Studio and need to debug it with command-line arguments. At the moment I just run the generated EXE file with the arguments I need (like this program.exe -file.txt) , but this way I can't debug. Is there somewhere I can specify the arguments for debugging?

2

16 Answers 16

912

Yes, it's in the Debug section of the properties page of the project.

In Visual Studio since 2008: right-click on the project node, choose Properties, go to the Debugging section -- there is a box for "Command Arguments".

On a more recent version of Visual Studio, you'll find it in "Project Debug Properties" under the run button:

Image of the visual studio run button's context menu, the second item on it says "{project name} debug properties}" Image of a window titled "Launch Profiles" where the first text box in it is titled "Command Line Arguments"

Sign up to request clarification or add additional context in comments.

8 Comments

Stackoverflow is the only usable MS documentation!
Be careful with that. This will not change the actual project file, but the vcxproj.user-file instead.
Note: if you have multi project in a solution, remember to right click the project you wand to run and "Set as StartUp Project".
Spot on. But apparently in VS2017 it's not called "Debugging", but "Debug". We may never know why.
Make sure you have the correct Configuration selected in the dropdown at the top of the Property pages, i.e. the same configuration as the one you are trying to run.
|
62

The Mozilla.org FAQ on debugging Mozilla on Windows is of interest here.

In short, the Visual Studio debugger can be invoked on a program from the command line, allowing one to specify the command line arguments when invoking a command line program, directly on the command line.

This looks like the following for Visual Studio 8 or 9 (Visual Studio 2005 or Visual Studio 2008, respectively)

  devenv /debugexe 'program name' 'program arguments'

It is also possible to have an explorer action to start a program in the Visual Studio debugger.

Comments

21

Even if you do start the executable outside Visual Studio, you can still use the "Attach" command to connect Visual Studio to your already-running executable. This can be useful e.g. when your application is run as a plug-in within another application.

1 Comment

Yep, attach with Ctrl+Alt+P (or click "Debug" > "Attach to process..."). But this doesn't really answer OP question ;)
21

In Visual Studio 2022, the option to specify "Command line arguments" has been moved to "Launch Profiles UI" (screenshot below).

You can open it from Right-click project > properties > Debug > "Open debug launch profiles UI" > Command line arguments

Screenshot of Launch profile UI in Visual Studio 2022


Note that this feature is currently receiving negative feedback from users. References below:

2 Comments

You can access the Launch Profiles dialog much faster. Either via menu bar: Debug[project_name]: Debug Properties. Or via the drop-down menu available on the green Debug button in toolbar.
I had to restart my Visual Studio to these things to appear... I mean all these solution made no sense so I just decided to restart the entire app. And then it just works...
9

Microsoft Visual Studio Ultima 2013.

You can just go to the DEBUG menu → Main PropertiesConfiguration propertiesDebugging and then you will see the box for the command line arguments.

Actually, you can set the same input arguments for all the different configurations and not only for debugging.

From the pull down menu of configuration select: All Configurations and insert the input arguments (each argument separated by space).

Now, you can execute your program in different modes without having to change the input arguments every time.

1 Comment

It kinda works like that in MS VS 2015 as well. Before I headed to "Debug-> {projectname} properties" I had to open the "Configuration Manager" accessable via the Dropdown containing by default "Debug" and "Release". A window popped up where I was able to add new "Configuration" items. These items are available in "Debug -> {projectname} properties".
6

In VS 2022 it is possible to debug any executable. Open a folder containing .exe file

  • Right-click on .exe file and click "Set as Startup item"

  • Again right-click on .exe file and click "Add Debug Configuration" or "Open Debug and Launch Settings" if configuration file is already created.

  • Add args to launch.vs.json, e.g.

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "default",
      "project": "ffprobe.exe",
      "projectTarget": "",
      "name": "ffprobe.exe",
      "args": [ "C:\\Temp\\test-file" ]
    }
  ]
}
  • Right-click on .exe file and click "Debug"

Comments

5

With VS 2015 and up, Use the Smart Command Line Arguments extension. This plug-in adds a window that allows you to turn arguments on and off:

Smart Command Line Arguments interface

The extension additionally stores the arguments in a JSON file, allowing you to commit them to source control. In addition to ensuring you don't have to type in all the arguments every single time, this serves as a useful supplement to your documentation for other developers to discover the available options.

Comments

3

Right click on the project in the Solution window of Visual Studio, select "Debugging" (on the left side), and enter the arguments into the field "Command Arguments":

Enter image description here

Comments

3

In Visual Studio 2017 with a .NET Core console application do the following:

Right click on the Project in the Solution window, select "Properties", Debug (on the left side), and enter the arguments into the field "Application Arguments".

Note that they should be space-separated.

Comments

2

This may help some people who still have problems. I use Visual Studio 2015 and I could only pass the arguments when I changed the definition of argv.

Instead of

int main(int argc, char **argv){
}

I had to use

int main(int argc, char *argv[]){
}

I do not know why it was necessary, but it works.

1 Comment

Had the same issue but both declarations mentioned above didn't work. Solution was changing platform from x86 to x64 since I am working on a 64bit machine.
2

I found some old command line arguments stored in a MyStartUpProject.csproj.user file under my startup-project's source folder. Deleting this file didnt work, Visual Studio brought it back for me. I had to edit the arguments in the file.

The values in the file did not show up in VS, Project Properties, Debugging. Entering values there appended them to the values in the mysterious MyStartUpProject.csproj.user file.

1 Comment

Wild - thank you for this...I knew there had to be some old visual studio nonsense lying around...
1

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. If you are tired of changing in the properties then temporarily give the input directly in the program.

Comments

1

Besides adding parameters in project startup properties, debugger can be attached to a running program, at any time after starting it. A call to DebugBreak or to __debugbreak can be added into the code.
https://learn.microsoft.com/en-us/visualstudio/debugger/debugbreak-and-debugbreak?view=vs-2022
So, the program will break and wait for a debugger to be attached, or to ignore it. As result the debugger will be attached in exactly place you need it.
Some other way is to start the program and attach the debugger at runtime as native, .NET or Script, check debugger menus in Visual Studio. This way you will probably not be sure what code runs in the moment you attach the debugger, but you don't always need.
But, I would also consider identifying exactly the pieces of code I want to debug, then making unit tests. So, much easier and faster to debug small pieces of unit tests.

Comments

1

I am using CMake with Visual Studio. On VS 2022 (17.11.2), this is how I get to the launch.vs.json.

enter image description here

Once in launch.vs.json, here's how I add the command line argument to pass.

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "default",
      "project": "CMakeLists.txt",
      "projectTarget": "TS.exe",
      "name": "TS.exe",
      "args": [
        "-r "
      ]
    }
  ]
}

Comments

0

For those using VS2022 and you don't have launchSchema.json, as someone mentioned above, there is a solution for inserting args using launchSettings.json.

enter the file and insert your args using "commandLineArgs": "argument here",

this worked for me.

1 Comment

And the file is located in this project sub-folder \My Project\launchSettings.json. If you modify the file directly you need to reload the project
0

As of 2025, none of these above recommended solution work for me on Visual Studio 2022. When I click the properties of the project, it is empty. When I try to find it on menu, it does not exist on menu anymore. However, they do allow you to edit launch.vs.json by clicking Debug -> Debug and Launch settings for xxx, which allows you to pass an args parameter array. It works like a charm for me.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.