for /f 立即关闭cmd提示符

发布于 2024-12-02 00:41:20 字数 365 浏览 2 评论 0原文

当我打开 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仲春光 2024-12-09 00:41:20

这家伙似乎成功解决了一个非常相似的问题:

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.

提笔落墨 2024-12-09 00:41:20

添加括号“(”,如下所示:

for %q in ('a') do (

它将在以下几行中提示您“更多?”,直到您决定用“)”关闭 for 块

Add a paranthesis "(", like this:

for %q in ('a') do (

It will prompt you with a "More?" in the following lines until you decide to close your for block with a ")"

—━☆沉默づ 2024-12-09 00:41:20

查看 'FOR' ('FOR /?') 的帮助,您可以看到 '/F' 选项用于解析文件输入并具有以下选项:

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

注意最后一个条目...单引号值是被视为要运行的命令,该命令的输出就是“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:

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文