Send command-line arguments to a debugee (C++)
In Visual C++, use the command-line arguments dropdown to quickly specify or reuse arguments for debugging.
Prerequisites
- Visual Studio 2022 version 17.12 preview 5 or later.
- Visual Studio Tools for Unreal Engine. See Install Visual Studio Tools for Unreal Engine) for installation instructions.
Specify command-line arguments
The command-line arguments dropdown is available in the Standard toolbar. If the Standard toolbar isn't visible, from the Visual Studio main menu choose Tools > Customize. In the Customize dialog, choose Toolbars. Then select Standard.
The Toolbars tab is selected in the Customize dialog. The entry for Standard, meaning the standard toolbar, is selected.
The command-line arguments dropdown follows the Solutions Platforms dropdown on the Standard toolbar. If no arguments have been specified, the dropdown is empty and the tooltip displays "empty".
The command-line arg dropdown is shown following the Solutions Platforms dropdown on the Standard toolbar. The dropdown is empty. A tooltip reads, "empty".
When you add command-line arguments, the tooltip shows the selected argument list so that you can see all of the arguments.
To add command-line arguments, type them in the dropdown and press Enter. The arguments are saved in the order that you enter them and appear in the dropdown for future use. There's a limit of five command lines that you can add before the oldest one is removed to make room for a new one.
In this example, the command-line argument -arg1
is added to the dropdown:
Adding another argument, -arg2
, results in:
You can use the dropdown to select previously specified command-line arguments to pass to the app you're debugging. Consider the following code:
#include <iostream>
int main(int argc, char* argv[])
{
for (int i = 1; i < argc; ++i) // argv[0] is the path of the running program
{
std::cout << "Argument " << i << ": " << argv[i] << std::endl;
}
return 0;
}
In this example, the -arg1 -arg2
arguments are selected in the command-line arguments dropdown:
Which results in this output when the app is run:
Argument 1: -arg1
Argument 2: -arg2
The command-line arguments dropdown is a convenient way to specify and reuse command-line arguments. Particularly when you need to quickly switch between different arguments for different scenarios you're testing.
You can also click in the command-line arguments dropdown and press Ctrl+C to copy the highlighted command-line to the clipboard.
Relationship to project settings
Another way to specify command-line arguments is in project settings.
If you right-click the project in the Solution Explorer and choose Properties, you can specify command-line arguments in Debugging > Command Arguments.
The Command Arguments entry is shown and it has the same arguments as the command-line arguments dropdown: -arg1 -arg2.
Command-line arguments specified in the project settings are added to the command-line arguments dropdown. Conversely, if you select arguments in the command-line arguments dropdown, they replace the arguments specified in the project settings. Either way you specify the arguments, they're kept in sync. Both are saved with the project settings, so they're available when you reopen the project.