2013-10-18 19 views
4

說實話,我不期望一個令人滿意的答案here.These命令不能被調用,就是這樣(據我所知,唯一的命令不能用於調用)。 這裏是他們的輸出幾個例子:爲什麼我不能在批處理和cmd中都不能調用「IF」和「FOR」?

C:\Windows\system32>call @if a==a echo called 
',' is not recognized as an internal or external command, 
operable program or batch file. 

C:\Windows\system32>call (@if a==a echo called) 
';' is not recognized as an internal or external command, 
operable program or batch file. 

C:\Windows\system32>call if a==a echo called 
'if' is not recognized as an internal or external command, 
operable program or batch file. 

C:\Windows\system32>call for %a in (1) do @echo called 
'for' is not recognized as an internal or external command, 
operable program or batch file. 

C:\Windows\system32>call @for %a in (1) do @echo called 
'+' is not recognized as an internal or external command, 
operable program or batch file. 

C:\Windows\system32>call (@for %a in (1) do @echo called) 
';' is not recognized as an internal or external command, 
operable program or batch file. 

我有一些懷疑,認爲如果並沒有在事實上「真正的」命令 - 他們只是決定通過命令提示符控制線(或支架塊)在他們後面或不在後面,這使呼叫混淆。 反正即使這樣,當有語法錯誤在呼籲或者如果他們發現:

C:\Windows\system32>call (@if a= echo called) 
= was unexpected at this time. 

C:\Windows\system32>call (for %a (1) do echo called) 
(1 was unexpected at this time. 

所以至少解析完成。

回答

7

你說得很對。

FORIFREM正常內部命令(但對於REM也存在一個正常的內部版本)。
他們使用自己的特殊解析器(每個都是不同的解析器)。

看來,這些命令被翻譯成一種令牌。
因此,你得到了這樣的意外錯誤消息(有更多的可能的字符),錯誤/標記字符也取決於Windows版本(如果我沒有記錯的話)。
可能CALL命令僅查看來自原始命令的標記化數據。

命令塊根本無法使用call命令,&|<>也無法正常工作。

call (a^|a) 

搜索命令/令牌2,所以如果你創建了一個名爲批處理文件2.bat你可以用call (a^|a)啓動它。

更多信息有關CALL
Dostips:CALL me, or better avoid call
Dostips:Limit CMD processing to internal commands, safer and faster?

+0

這是令人着迷的 – user1167442

4

畢竟這是可以調用如果並..或差不多;

@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 

儘管我看不到這個用法。

+3

+1這是令人印象深刻的東西,你已經測試(不僅這些)。從而你發現了許多互動的東西 – jeb

相關問題