Why I can't CALL “IF” and “FOR” neither in batch nor in the cmd?

前端 未结 3 1740
不知归路
不知归路 2020-12-01 15:35

To be honest I don\'t expect a satisfying answer here.These command cannot be called and that\'s it (as far as I know the only commands that cannot be used with call). Here

相关标签:
3条回答
  • You are quite right.

    FOR, IF and REM aren't normal internal commands (but for REM exists also a normal internal version).
    They use an own special parser (each a different one).

    It seems that these commands are translated to a sort of token.
    Therefor you got such unexpected error messages (there are much more possible characters), the error/token character depends also of the Windows version (if I remember correct here).
    Probably the CALL command sees only the tokenized data from the original command.

    Command blocks don't work at all with the call command, also &|<> don't work as expected.

    call (a^|a)
    

    Searches for a command/token 2, so if you create a batch file named 2.bat you can start it with call (a^|a).

    For further information about CALL
    Dostips:CALL me, or better avoid call
    Dostips:Limit CMD processing to internal commands, safer and faster?

    0 讨论(0)
  • 2020-12-01 16:04

    this way works : call cmd.exe /c if a==a echo called.

    0 讨论(0)
  • 2020-12-01 16:08

    After all it is possible to call IF and FOR ..or almost;

        @echo off
    
    rem :: this will produce an error
    rem if a equ a
    
    rem :: And this too
    rem call if a equ a rem
    
    rem :: But this will not!!!
    call if a equ a
    
    rem :: This will not too ((\but in command prompt single % is enough)
    call for %%%%a in (.) do
    
    rem :: And this
    call if a equ a for %%%%a in (.) do if 1 equ 1  for %%%%a in (.) do if c==c
    
    rem :: And this
    call if a equ a for %%%%a in (.) do if 1 equ 1 for %%%%a in (.) do if c==c ( rem rem rem echo something
    

    Despite I see no usage of this.

    0 讨论(0)
提交回复
热议问题