【问题标题】:Create A Batch File Within Batch File - Echo ">NUL"在批处理文件中创建批处理文件 - Echo ">NUL"
【发布时间】:2013-09-25 09:22:20
【问题描述】:

情况:

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

我似乎想不出任何方法来导出/回显“NUL”sn-p..任何输入都将不胜感激!

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

【问题讨论】:

    标签: windows batch-file echo nul


    【解决方案1】:

    您需要转义特殊字符,以便解析器知道您要回显哪些部分以及要执行哪些部分。

    顺便说一句。重定向一个完整的块更容易

    (
      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% 包含空格或特殊字符时,引号很有用

    【讨论】:

    • 由于某种原因,当我在块内有回声时,它会导致问题。它显然执行了 echo 并从我执行 .bat 文件的位置创建了一个 .txt 文件。此外,当它回显/执行时,它不会将回显回显到实际的“ObserveLog.bat”。抱歉,如果这听起来令人困惑,我现在已经有点困惑了……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 2019-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多