windows “在这个时候出乎意料。”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7769591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:49:29  来源:igfitidea点击:

"was unexpected at this time."

windowserror-handlingbatch-file

提问by Ricardo Moura

I'm running this command on a batch file:

我在批处理文件上运行此命令:

for %I in (*.txt *.doc) do copy %I c:\test2

...and it keeps returning:

...它不断返回:

I was unexpected at this time.

这个时候出乎我的意料。

What is the cause of this error?

这个错误的原因是什么?

回答by paxdiablo

If you're running within a batch/cmd file, you need to doublethe %markers:

如果您在批处理/cmd 文件中运行,则需要将标记加倍%

for %%i in (*.txt *.doc) do copy %%i c:\test2

The single %variant only works from the command line.

单一%变体仅适用于命令行。

回答by jsvk

If being run from a batch file, variables need to be denoted with two percent signs, like %%I, only from the command line you use one

如果从批处理文件运行,变量需要用两个百分号表示,例如%%I,仅在命令行中使用一个

回答by C Johnson

I ran across a case where I was getting this error from a file that was named *.cmd. The error arose when I tried to access the first argument to the batch command:

我遇到了一个案例,我从名为 *.cmd 的文件中收到此错误。当我尝试访问批处理命令的第一个参数时出现错误:

if %1 EQU ""

Once I put quotes around the symbol for the first argument, the warning message went away:

一旦我在第一个参数的符号周围加上引号,警告消息就消失了:

if "%1" EQU ""

回答by Overdrivr

Not a direct answer to the question, but if you encounter this message in any program, batch command, etc. then it's most likely related to your PATH containing "characters.

不是问题的直接答案,但如果您在任何程序、批处理命令等中遇到此消息,那么它很可能与您的 PATH 包含"字符有关。

For instance, in Atom editor I was getting the message in the settings view.

例如,在 Atom 编辑器中,我在设置视图中收到消息。

"\"GNU was unexpected at this time

This was due to a different program putting in my PATH the following entry

这是由于不同的程序在我的 PATH 中放置了以下条目

...;C:\"Program Files"\"GNU ARM Embedded;..."

Because of that, the antislash character is read as escaped by some programs, which causes issues because then it's not a pathname delimiter but a simple character.

因此,反斜杠字符被某些程序读取为转义字符,这会导致问题,因为它不是路径名分隔符而是一个简单字符。

The solution for me was to remove those "from the PATH, and everything worked fine.

我的解决方案是"从 PATH 中删除它们,一切正常。

...;C:\Program Files\GNU ARM Embedded;...

PS: I have a doubt whether or not this can impact the original program (GNU ARM Embedded in this case) that maybe does not support spaces in pathnames. If somebody with more insight can clarify in the comments, I will update my post.

PS:我怀疑这是否会影响可能不支持路径名中的空格的原始程序(在这种情况下为 GNU ARM Embedded)。如果有更深入了解的人可以在评论中澄清,我会更新我的帖子。

Hope this helps

希望这可以帮助