Semedar
Semedar

Reputation: 35

Create A Batch File Within Batch File - Echo ">NUL"

Situation:

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

Upvotes: 2

Views: 4842

Answers (1)

jeb
jeb

Reputation: 82337

You need to escape special characters, so the parser knows which parts you want to echo and which ones you want to be executed.

Btw. It's easier to redirect a complete 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

I also changed the type %UserProfile%.. to type "%%UserProfile%%..." else you get the expanded version in your observeLog.bat The quotes are useful when %UserProfile% contains spaces or special characters

Upvotes: 5

Related Questions