简体   繁体   English

命令在命令提示符中有效,但在批处理文件中无效

[英]Command works in Command Prompt but not in a batch file

Trying to print out the 8dot3 name of a file, it does works when I paste the line in the Command Prompt but not when I run it from a batch file.试图打印出文件的 8dot3 名称,当我在命令提示符中粘贴该行时它确实有效,但当我从批处理文件中运行它时则无效。

Result when pasted :粘贴时的结果:

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

8088_O~1.COM

Result from batch file :批处理文件的结果:

D:\tmp>lfn.bat

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

~nxsA was unexpected at this time.

What else is needed to make it work inside a batch file ?还需要什么才能使其在批处理文件中工作?

you need to escape % is batch files你需要转义 % 是批处理文件

just type cmd /e:on /c for %%A in (8088_othello.com) do @echo %%~nxsA只需在 (8088_othello.com) 中为 %%A 键入 cmd /e:on /c 做 @echo %%~nxsA

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM