cdebuggingvisual-studio-2017commandargument

Debugging with "Command Arguments" in Visual Studio not working


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


Solution

  • 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.