【问题标题】:Command works in Command Prompt but not in a batch file命令在命令提示符中有效,但在批处理文件中无效
【发布时间】:2013-08-14 02:41:36
【问题描述】:

试图打印出文件的 8dot3 名称,当我将该行粘贴到命令提示符时它确实有效,但当我从批处理文件运行它时无效。

粘贴后的结果:

D:\tmp>cmd /e:on /c for %A in (8088_othello.com) do @echo %~nxsA

8088_O~1.COM

批处理文件的结果:

D:\tmp>lfn.bat

D:\tmp>cmd /e:on /c for ~nxsA

~nxsA was unexpected at this time.

还需要什么才能使其在批处理文件中工作?

【问题讨论】:

  • 我的问题是编码。当我将 bat 文件设为 utf-8 时,一切正常。以前它在 ucs-2 上

标签: windows command-line batch-file


【解决方案1】:

你需要转义%是批处理文件

只需输入 cmd /e:on /c for %%A in (8088_othello.com) do @echo %%~nxsA

【讨论】:

  • ss64.com/nt/syntax-esc.html - 它既适用于 for 循环,也适用于其他应用程序
  • 很好的解决方案。立即解决了我的问题。我一直以为.bat=直接cmd脚本
  • 我只是将 %% 加倍,就可以了,谢谢
猜你喜欢
  • 1970-01-01
  • 2013-05-28
  • 1970-01-01
  • 1970-01-01
  • 2020-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多