情况:
- 我有一个经常更新的文本日志文件。
- 我已经有一个可以手动检查的批处理文件。
- 我希望它(在批处理启动时)创建一个新的 .bat。
- 我在导出/创建“
timeOut/t 2 >NUL
”时遇到问题 部分。 - 它不会导出 >NUL 部分;留下一个空格。
- 示例:
超时/t 2/noBreak
I can't seem to figure out any way to export/echo out that ">NUL" snippet.. Any input would be appreciated!
echo mode con:cols=80 lines=28 >> %UserProfile%\Desktop\observeLog.bat
echo @echo off >> %UserProfile%\Desktop\observeLog.bat
echo Title Error Log >> %UserProfile%\Desktop\observeLog.bat
echo :startLogObserve >> %UserProfile%\Desktop\observeLog.bat
echo type %UserProfile%\Desktop\testLog.txt >> %UserProfile%\Desktop\observeLog.bat
echo timeout /t 2 >NUL /noBreak >> %UserProfile%\Desktop\observeLog.bat
echo cls >> %UserProfile%\Desktop\observeLog.bat
echo goTo :startLogObserve >> %UserProfile%\Desktop\observeLog.bat
最佳答案
您需要转义特殊字符,以便解析器知道您想要回显哪些部分以及想要执行哪些部分。
顺便说一句。重定向整个 block 更容易
(
echo mode con:cols=80 lines=28
echo @echo off
echo Title Error Log
echo :startLogObserve
echo type "%%UserProfile%%\Desktop\testLog.txt"
echo timeout /t 2 ^>NUL /noBreak
echo cls
echo goTo :startLogObserve
) > %UserProfile%\Desktop\observeLog.bat
我还将type %UserProfile%..
更改为type“%%UserProfile%%...”
,否则您将在observeLog.bat中获得扩展版本
当 %UserProfile%
包含空格或特殊字符
关于windows - 在批处理文件中创建批处理文件 - Echo ">NUL",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18909124/