for /f 立即关闭cmd提示符
当我打开 cmd.exe 并键入第一行并按 ENTER 时,它工作正常。当我输入另一行并按 ENTER 时,它立即关闭。
我可以将 ('a') 更改为 ('asdfgh') 那么同样的问题。或%q 到%f 同样的问题。
区别在于 /f,由于某种原因,带有 ('......') 的 FOR /F 会导致 cmd.exe 关闭。
这发生在我的一个系统上,而不是另一个系统上
C:\>for %q in ('a') do echo %q <ENTER>
C:\>echo 'a'
'a'
C:\>for /f %q in ('a') do echo %q <ENTER>
When I open cmd.exe and type that first line and push ENTER, it works fine. When I input that other line and push ENTER, it closes immediately.
I can change ('a') to ('asdfgh') then same problem. or %q to %f same problem.
The difference is the /f, for some reason the FOR /F with ('......') causes cmd.exe to close.
This happens on one of my systems and not another
C:\>for %q in ('a') do echo %q <ENTER>
C:\>echo 'a'
'a'
C:\>for /f %q in ('a') do echo %q <ENTER>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这家伙似乎成功解决了一个非常相似的问题:
for /f 立即关闭 cmd 窗口
这种情况下的问题与
COMSPEC
环境变量有关,看起来它最初设置不正确。该男子申请注销 Windows 帐户并重新登录。This guy seems to have solved a very similar problem successfully:
for /f closes cmd window immediately
The problem in that case turned out to have to do with the
COMSPEC
environment variable, it being incorrectly set initially, as it seems. The guy applied logging out of the Windows account and back in.添加括号“(”,如下所示:
它将在以下几行中提示您“更多?”,直到您决定用“)”关闭 for 块
Add a paranthesis "(", like this:
It will prompt you with a "More?" in the following lines until you decide to close your for block with a ")"
查看 'FOR' ('FOR /?') 的帮助,您可以看到 '/F' 选项用于解析文件输入并具有以下选项:
注意最后一个条目...单引号值是被视为要运行的命令,该命令的输出就是“FOR”正在解析的内容。
也许您在一台机器上有“a”命令/可执行文件,但在另一台机器上没有?
仅当您特别想要“/F”提供的行为时,才应使用“/F”标志。
Looking at the help for 'FOR' ('FOR /?'), you can see that the '/F' option is for parsing file input and has the following options:
Note that last entry... a single-quoted value is treated as a command to run, and the output of that command is what 'FOR' is parsing.
Perhaps you have an 'a' command/executable on one machine, but not on the other?
You should only be using the '/F' flag if you specifically want the behavior that '/F' supplies.