2

Situation:

  • I have a text log file that gets updated frequently.
  • I already have a batch file that can check it manually.
  • I want it (upon start-up of batch) to create a new .bat.
  • I'm having problems exporting/creating the "timeOut /t 2 >NUL" part.
  • It won't export the >NUL part; leaves a blank space.
  • Example: 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
Semedar
  • 35
  • 1
  • 2
  • 10

1 Answers1

5

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

jeb
  • 78,592
  • 17
  • 171
  • 225
  • For some reason when I have an echo within the block, it causes problems. It apparently executes the echo and creates a .txt file from where ever I executed the .bat file. Also, when it echos/executes, it doesn't echo out the echo to the actual "ObserveLog.bat". Sorry if this sounds confusing I'm kinda confused already right now explaining this.. – Semedar Sep 21 '13 at 19:39