4

I've set the command line args for my app in the project properties -> debugging -> command arguments section.

If I run the program from command line directly I do:

progname arg1 arg2

So I've set the command line arguments in VS to

arg1 arg2,

as described here.

But, the program doesn't seem to run the same way as in running it from command line. The arguments are text files, and in the command line it can load those text files correctly, in VS2010 it doesn't somehow. Any ideas why?


Edit: update/clarification of post:

I am not getting any exceptions.

I may have oversimplified the problem too much in my explanation. I'm not actually loading text files, I'm loading a physics engine, which should be determined at runtime, so I need command line arguments.

The code used for loading the physics engine, on a high level, is:

if ( argc > 2 )
{
    #ifndef PAL_STATIC
        PF->LoadPALfromDLL(); 
    #endif
        //DebugBreak(); // for debugging ;)
        PF->SelectEngine(argv[1]);

        if (!pp) {
    #ifdef _WIN32
            MessageBox(NULL,L"Could not start physics!",L"Error",MB_OK);  

         /* ^ This is the error I am getting, i.e. pp is NULL, 
         so "PF->SelectEngine(argv[1]);" is not loading engine correctly */

    #else
            printf("Could not start physics engine %s!\n",argv[1]);
    #endif

    return -1;
}

I am using Bullet, which is run like this:

progname.exe arg1 arg2, 

arg1 is the physics engine name and arg2 is a physics file to load, but it hangs on arg1.

The specific way I invoke this on the command line is:

progname.exe Bullet filename. 

If i do this on command line it works, but if I pass these arguments to the debugger, I get a problem saying could not load physics engine.

This may be a result of the internals of the physics engine loader, which is from another source, but my guess is that this should work the same way whether I pass these arguments in the command line or in the debugger settings of VS.

I will look into the UAC settings and see what they say.

Community
  • 1
  • 1
ChrisC
  • 892
  • 2
  • 12
  • 33
  • Are you loading the text files with absolute paths, or relative paths ("C:\temp\blah.txt" vs "blah.txt")? My guess is the app running through VS is using a different assembly location path. – Adam Plocher Apr 01 '13 at 02:01
  • absolute, eg E:/path/file.txt, maybe ill try windows backslash? – ChrisC Apr 01 '13 at 02:10
  • backslash also not working – ChrisC Apr 01 '13 at 02:11
  • Strange, can you step through the code and see what it's doing? As long as you're putting the parameters in exactly the same as you do when not running through the debugger, it should work I would think... – Adam Plocher Apr 01 '13 at 02:28
  • yep, the weird thing is that i can see the filename loaded correctly as a string within the code when debugging, i.e. when i hover over the filename variable it displays the correct file name, seemingly just as when i were to run it from command line, but actually loading the file within code from the file name doesnt work anymore, if you know what i mean. i guess a work around would be to run the prog from command line and attaching it to vs then, but that seems rather annoying ^^ – ChrisC Apr 01 '13 at 02:37
  • again, running a different program that i also need at the moment, i get different behaviour running it from within vs and from command line. this porgram doesnt use command line args at all. what the hell? ^^ – ChrisC Apr 01 '13 at 03:09
  • Perhaps it has something to do with UAC? Does the instance running Visual Studio (and starting your process) not have access to the file that's trying to be read, but running it by itself does? You're not receiving any exceptions or errors during runtime? – Adam Plocher Apr 01 '13 at 03:55
  • have edited post above at section "Edit: update/clarification of post:" if anyone is still following this ^^ meanwhile , i will take a look at UAC settings as Adam suggested. Thanks for all the help so far! :) – ChrisC Apr 04 '13 at 23:01
  • oh, i just see since were not talking about loading a file directly, but loading a physics engine from a stringname, i don't think UAC settings apply. I hope I didn't mislead anyone too much,sorry! again, if anyone is aware of what may be causing this, I would really appreciate any help! Thanks again! :) – ChrisC Apr 04 '13 at 23:10
  • 2
    For debugging this problem, I'd hardcode the correct path in a variable instead of reading it from command line arguments. See if bullet starts from command line but not from debugging with the hardcoded path, too. I'd expect that the problem is the environment (working folder, admin rights, environment variables,...) set up by VS instead of the string passed. – No answer Dec 05 '13 at 13:23

1 Answers1

0

As it says in : https://msdn.microsoft.com/en-us/library/17w5ykft.aspx, you can try adding a backslash to every "\" character, to escape them inside the path. For example :

Before : "C:\somewhere\someplace\physics_engine"

After : "C:\\somewhere\\someplace\\physics_engine"

Lorenzo
  • 591
  • 7
  • 18