这个问题扩大了对这个删除答案的意见。 我声称PATH中未扩展的variables引用在search可执行文件时不会被扩展,但Ken说他没有看到我所做的同样的行为。
请注意,普通的情况微妙而严重不同:在某些条件下,当从registry中的信息构buildpath环境variables时,环境variables会自动扩展。 我正在谈论的情况是,由于种种原因,这种情况没有发生,因此cmd.exe进程的实际环境块包含一个仍然具有环境variables引用的PATH。
这里是我build立的代码来testing这种行为:
md test1 echo echo hello! > test1test1.cmd set TESTPATH=%cd%test1 set percent=%% set PATH=c:windowssystem32;c:windows;c:windowssystem32Wbem;%percent%TESTPATH%percent% set PATH set TESTPATH test1 cmd /c test1 start test1.cmd
这是我的机器上的结果:
Windows任务计划程序不允许python subprocess.popen
简单的安装方法需要Windows / Batch Reference吗?
FTP使用batch file
批量游戏退出,而不是去下一行
C:workingtestpath>test C:workingtestpath>md test1 C:workingtestpath>echo echo hello! 1>test1test1.cmd C:workingtestpath>set TESTPATH=C:workingtestpathtest1 C:workingtestpath>set percent=% C:workingtestpath>set PATH=c:windowssystem32;c:windows;c:windowssystem32 Wbem;%TESTPATH% C:workingtestpath>set PATH Path=c:windowssystem32;c:windows;c:windowssystem32Wbem;%TESTPATH% PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.py;.pyw C:workingtestpath>set TESTPATH TESTPATH=C:workingtestpathtest1 C:workingtestpath>test1 'test1' is not recognized as an internal or external command,operable program or batch file. C:workingtestpath>cmd /c test1 'test1' is not recognized as an internal or external command,operable program or batch file. C:workingtestpath>start test1.cmd The system cannot find the file test1.cmd.
什么是预期的行为? 它根据Windows版本和/或其他因素而有所不同?
SETX不会将path追加到系统pathvariables
使用Windowsbatch file运行可执行文件
ForFiles不适用于具有dynamic文件夹名称的recursion文件夹
当一个ant文件调用一个调用ant文件的batch file时如何失败
batch file命令在新窗口中打开不同的命令
这个问题有两个截然不同的观点:
问:如何扩展嵌入另一个变量的值? 这一点不是特定于PATH变量,而是适用于任何人。
答:将感叹号中的变量名称括起来,当想要展开这样的值时启用延迟扩展:
@echo off setlocal EnableDelayedExpansion set TESTPATH=%cd%test1 set "PATH=c:windowssystem32;c:windows;c:windowssystem32Wbem;^!TESTPATH^!" set PATH echo PATH=%PATH%
问:当使用PATH定位可执行文件时,cmd.exe是否会延迟扩展?
答:不可以.cmd.exe使用PATH变量中的值,因为它们不会进一步处理。 任何可能出现在PATH中的特殊字符,如百分号或感叹号,都是从字面上理解的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。