为什么我不能调用“IF"?和“为"既不在批处理中也不在 cmd 中? [英] Why I can't CALL "IF" and "FOR" neither in batch nor in the cmd?

查看:22
本文介绍了为什么我不能调用“IF"?和“为"既不在批处理中也不在 cmd 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

老实说,我不希望在这里得到令人满意的答案.无法调用这些命令,仅此而已(据我所知,唯一不能与 call 一起使用的命令).以下是一些输出示例:

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 are few examples with their output:

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

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

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

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

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

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

我有些怀疑,IF 和 FOR 实际上不是真正的"命令——它们只是决定是否将命令提示符控制传递给它们后面的行(或括号块),这会混淆调用.无论如何,当在调用的 FOR 或 IF 中检测到语法错误时:

I have some suspicious , that IF and FOR are not in fact 'real' commands - they just decide to pass the command prompt control to the line (or brackets block) behind them or not , which confuses the call. Anyway even that , when there are syntax errors in called FOR or IF they are detected:

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

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

所以至少解析完成了.

推荐答案

你说得对.

FORIFREM 不是正常内部命令(但对于 REM 也存在正常的内部版本).
他们使用自己的特殊解析器(每个解析器都不同).

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).

似乎这些命令被翻译成一种标记.
因此,您收到了如此意外的错误消息(有更多可能的字符),错误/令牌字符还取决于 Windows 版本(如果我记得这里正确的话).
可能 CALL 命令只能看到来自原始命令的标记化数据.

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)

搜索命令/令牌 2,因此如果您创建一个名为 2.bat 的批处理文件,您可以使用 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).

有关CALL
的更多信息Dostips:给我打电话,或者最好避免打电话
Dostips:限制 CMD 处理内部命令,更安全更快?

这篇关于为什么我不能调用“IF"?和“为"既不在批处理中也不在 cmd 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆