1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to? %_CMDLine not working the way I thought the documentation says it does...

Discussion in 'Support' started by mathewsdw, Feb 29, 2012.

  1. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    As usual, a TCC session (and there's not much there):
    Code:
      Wed  Feb 29, 2012  5:02:36p
    TCC  13.03.46  Windows 7 [Version 6.1.7601]
    [Z:\]type TestManualArgumentPassing.btm
    @Echo %%_CMDLine: %_CMDLine
    [Z:\]TestManualArgumentPassing abc def=ghi jkl
    %_CMDLine: TestManualArgumentPassing abc
     
    
    As you can easily see, only the name of the command and the first argument were output, everything after that was dropped.

    Now, from the documentation, "_CMDLINE returns the current command line. (This is most useful in key aliases.) If you specify it on the command line, it returns the contents of the command line with the %_cmdline name removed."

    I left the whole description in because I am not trying to use it the "most useful" way; specifically I want to pass stuff to a batch file that TCC's command line parsing for batch files destroys. (Just to be clear as to why I am trying to do this, when I wrote C++ programs in the past I almost always did "keyword" arguments in the format "/Keyword=value", and even though I've now switched to TCC batch files I'd like to maintain the same syntax because I want it to be totally "transparent" to the user (i.e., me) whether any give program is a C++ program or a batch file.

    And the reason this is a problem for me is because for reasons Rex told me many moons ago had to do with cmd.exe compatibility TCC "strips" the "=" sign from the argument list as seen by the batch file; i.e. "abc def=ghi jkl" becomes just "abc def ghi jkl" as seen by the batch file. Well this is a problem because I also write these things such that not coding the parameter at all lets it take a "default" value if there is one, whereas coding the parameter with no value specified (i.e. "/Keyword=") "nulls" the value of the parameter, i.e. it has no value at all rather than the default value. And it seems to me (bad memory playing a role here) %_CMDLine used to return the entire command line rather than just the command name followed by only the first parameter. (I must admit that I can't even imagine a case where that would be useful.)

    So what am I doing wrong? Is there any way just to get the command line exactly as it was entered?

    - Dan
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,307
    Likes Received:
    39
    Dan, I think %* may be what you're looking for.
     
  3. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,859
    Likes Received:
    83
    You're using the wrong variable -- you want %CMDLINE (no underscore). %_CMDLINE is intended for internal use (by key aliases), before the command line is parsed and executed.
     
  4. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    Thank you, guys. You are both correct (but %* is a little bit better because I then don't have to deal with the command name); and Rex, the fact that it's "%CMDLine: rather than "%_CMDLine" tells me that memory in the matter was only slightly bad. :)
     

Share This Page