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

标签 windows batch-file echo nul

情况:

  • 我有一个经常更新的文本日志文件。
  • 我已经有一个可以手动检查的批处理文件。
  • 我希望它(在批处理启动时)创建一个新的 .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/

相关文章:

windows - Autohotkey 中的多个光标

c - 为什么内存对齐会在结构内发生变化?

batch-file - 批处理 : Parse TXT Lines into Array

javascript - "Echoing"Node.js 中的图像

php - 使用方括号解码 JSON

windows - 将 Windows 7 UEFI 条目写入 NVRAM

windows - 当某些字段为空时,Windows 批处理文件如何从带分隔符的文本文件中正确读取数据?

Java-单击按钮时执行bat文件,然后关闭Java窗口

batch-file - 批处理文件运行 VBScript

php - 如何用php检查字符串是否在数组中?