8

VS not running WITH the "Command Arguments" I passed in. What am I not doing right?

Trying to work with "Command Arguments" in Visual Studio.
I broke it down to a simple little ConsoleApplication program in C.

#include "pch.h"
#include <iostream>

int main(int argc, char *argv[])
{
  printf("\nargv: ");
  for (int i = 0; i < argc; i++)
  {
    printf(" %s", argv[i]);
  }
  printf("\n");
}

I then set the "Command Arguments": Project: Properties: Debugging:"Command Arguments": mom

enter image description here

I hit the RUN button and this is displayed(my argument is not passed in):

argv:  C:\Users\jack\source\repos\ConsoleApplication45\Debug\ConsoleApplication45.exe

C:\Users\jack\source\repos\ConsoleApplication45\Debug\ConsoleApplication45.exe (process 1812) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

When I run from the command line I get (Works as I want it to with the parameter passed in: "mom"):

C:\Users\jack\source\repos\ConsoleApplication45\Debug>ConsoleApplication45.exe mom

argv:  ConsoleApplication45.exe mom

C:\Users\jack\source\repos\ConsoleApplication45\Debug>

Thank you for the link Jean-François Fabre:
Yes I had to change to x64 from x86.

enter image description here

jdl
  • 6,151
  • 19
  • 83
  • 132
  • 1
    related: https://social.msdn.microsoft.com/Forums/vstudio/en-US/4097114c-8678-46bb-ba3b-7a2da8514efc/visual-studio-2017-not-passing-command-line-arguments-to-the-application?forum=vsdebug – Jean-François Fabre Jan 14 '19 at 20:36
  • is your target really 64 bits? link above suggests to select "any CPU" rather than x64. – Jean-François Fabre Jan 14 '19 at 20:37
  • That did it Jean-François Fabre. Thank you. – jdl Jan 14 '19 at 20:43
  • The end program is x64. I am not used to passing in parameters in the debugger. This is new to me. – jdl Jan 14 '19 at 20:44
  • @jdl, so glad to hear that your issue is solved, please mark Jean-François Fabre's reply as answer when you have free time, that will help others easier search it, thanks :) – Sara Liu - MSFT Jan 15 '19 at 06:30

3 Answers3

5

As explained in https://social.msdn.microsoft.com/Forums/vstudio/en-US/4097114c-8678-46bb-ba3b-7a2da8514efc/visual-studio-2017-not-passing-command-line-arguments-to-the-application?forum=vsdebug, you are setting the arguments only for x64 target when you need to set them for some other CPU.

It's possible that you're running x86 instead, where the arguments are empty.

The best method is to set them to "Any CPU" as it is very unlikely to be different depending on your target processor.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
3

I think your main problem here is a mismatch of the solution configuration/debugging properties vs. what Platform you are actually debugging/running the solution under.

Make sure these are aligned.

Example - this configuration is for Platform: x64

enter image description here

When the solution is ran/debugged, you need to make sure you are debugging in the same platform:

enter image description here

If your Platform is not x64,then configure and run the project under Platform: x86 or All Platforms as suggested.

static_cast
  • 1,174
  • 1
  • 15
  • 21
2

I thought I was seeing a similar issue, but realized the problem was with the operation of the Property Pages dialog. In previous versions of Visual Studio, selecting a project and right-clicking Properties would open up the dialog with the configuration set to the active configuration.

With Visual Studio 2017 this is no longer the case, and seems to open with the last edited configuration, which is confusing and could lead to someone editing the setting for the wrong configuration, as seen above. Not a good change...

leona
  • 21
  • 1