home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 68,877 of 68,980   
   R.Wieser to All   
   Re: Comma in an argument value   
   05 Dec 24 11:34:22   
   
   From: address@is.invalid   
      
   Anton,   
      
   >> Remove the @ECHO OFF then you can see the executed command:   
   >>   
   >> FOR /F "tokens=2,* delims= " %A in ("a "b c" d e") DO SET ARGS=%B   
   ...   
   > It seems as though the comma is replaced by a space only within   
   > the FOR invocation.  If you asked "why?" as an exercise for the reader,   
   > then failed it.   
      
   Look at what is inside the "(" and ")".   
      
   What I see is is four double-quotes.  The "a " inside the first pair, and   
   the " d e" into the second.   The "b c" seem sto be *outside* any quoting.   
      
   Have you ever tried different inputs ?  Like removing the double-quotes when   
   calling your batch file ?  Like this :   
      
   test.bat a b,c d e   
      
   -or-   
      
   test.bat a 'b,c' d e   
      
   -or-   
      
   test.bat a ""b,c"" d e   
      
   You might notice FOR loop lines and different results.  With the last one   
   doing what you want, as the "b,c" is , in the FOR loop, again inside   
   double-quotes (and is regarded as a single unit).   
      
   By the way, for testing I added the following line above your "for" loop:   
      
   FOR /F "tokens=2* delims= " %%A in ("%*") DO echo [%%A][%%B]   
      
   Notice how the "[%%aA]" output differs from the %2 output.  That is because   
   the commandline and your FOR loop use different a parsing.   
      
      
   -- Assuming your arguments do *not* have any spaces in them (and no   
   double-quotes!) and you group arguments by using a comma (or anything not a   
   space) between them I would suggest to use multiple FOR loops for your   
   parsing:   
      
   FOR /F "tokens=1* delims= " %%A in ("%*") DO SET ARG1=%%A   
   FOR /F "tokens=2* delims= " %%A in ("%*") DO SET ARG2=%%A&SET ARGR=%%B   
   echo [%ARG1%][%ARG2%][%ARGR%]   
      
   Regards,   
   Rudy Wieser   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca