当使用^符号input带有参数的多行命令时,如果使用双引号来使用带空格的string,^符号也会被传递,任何人都可以解释这是什么方法吗?
working.cmd
@echo off call openfiles.cmd ^ C:dirfilename.txt ^ C:another_diranother_file.txt
notworking.cmd
@echo off call openfiles.cmd ^ "C:dir with spacesfile with spaces.txt" ^ "C:another dir with spacesanother file with spaces.txt"
openfiles.cmd看起来像
安全地获得批量当前日月份和年份
在.bat / .cmd程序中更改块内的variables
获取屏幕分辨率作为cmd中的variables
@echo off for %%x in (%*) do ( IF EXIST %%x ( call "c:Program FilesNotepad++notepad++.exe" %%x ) ELSE ( call echo Not found %%x ) ) pause
我得到的错误看起来像
C:>call openfiles.cmd "C:dir with spacesfile with spaces.txt" ^ ELSE was unexpected at this time.
将SAS Enterprise Guide解压缩到Unix Server可运行批次?
Windows CMD – 从batch file重置pathvariables?
如何识别.exe文件(Not Installed)是64位还是32位使用windows命令提示
将值传递给Windows命令的中间(运行时)input提示
如何使用batch file更改Windows中文件的“修改”时间戳?
脱字符规则:
如果下一个字符是换行符,则取下一个字符(即使这也是换行符)。
有了这个简单的规则,你可以解释一些事情
echo #1 Cat^&Dog echo #2 Cat^ &Dog echo #3 Redirect to > Cat^ Dog setlocal EnableDelayedExpansion set lineFeed=^ echo #4 line1!lineFeed!line2
#3创建一个名为“猫狗”的文件,因为空间已经被转义,不再作为分隔符。
但是仍然有可能打破这个规则!
你只需要把任何重定向放在脱字号的前面,它仍然会丢掉换行符(多行仍然有效),但是下一个字符不会被转义。
echo #5 Line1< nul ^ & echo Line2
所以你也可以用它来构建你的多行命令
call openfiles.cmd < nul ^ "C:dir with spacesfile with spaces.txt" < nul ^ "C:another dir with spacesanother file with spaces.txt"
或者使用宏
set "n=< nul ^" call openfiles.cmd %n% "C:dir with spacesfile with spaces.txt" %n% "C:another dir with spacesanother file with spaces.txt"
在尝试了一些不同的东西之后,我设法使它只用双引号的额外空间。 更改notworking.cmd以下工作
@echo off call openfiles.cmd ^ "C:dir with spacesfile with spaces.txt" ^ "C:another dir with spacesanother file with spaces.txt"
注意双引号前面的空格
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。