NUL"-6ren"> NUL"-情况: 我有一个经常更新的文本日志文件。 我已经有了可以手动检查的批处理文件。 我希望它(在批处理启动时)创建一个新的 .bat。 我在导出/创建“timeOut/t 2 >NUL”时遇到问题部分。 -6ren">
gpt4 book ai didi

windows - 在批处理文件中创建批处理文件 - Echo ">NUL"

转载 作者:可可西里 更新时间:2023-11-01 09:55:13 26 4
gpt4 key购买 nike

情况:

  • 我有一个经常更新的文本日志文件。
  • 我已经有了可以手动检查的批处理文件。
  • 我希望它(在批处理启动时)创建一个新的 .bat。
  • 我在导出/创建“timeOut/t 2 >NUL”时遇到问题部分。
  • 它不会导出 >NUL 部分;留下一个空白。
  • 示例: timeout/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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com