38

I want to create a log of every operation processed in a batch file and used the following but to no avail. How do I fix it (the file was not created)?

REM>> C:\"VTS\ADVANCED TOOLS\SYSTEM\LOG\Advanced tools %date%.log"
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mac
  • 507
  • 2
  • 5
  • 7

3 Answers3

78

You need to use ECHO. Also, put the quotes around the entire file path if it contains spaces.

One other note, use > to overwrite a file if it exists or create if it does not exist. Use >> to append to an existing file or create if it does not exist.

Overwrite the file with a blank line:

ECHO.>"C:\My folder\Myfile.log"

Append a blank line to a file:

ECHO.>>"C:\My folder\Myfile.log"

Append text to a file:

ECHO Some text>>"C:\My folder\Myfile.log"

Append a variable to a file:

ECHO %MY_VARIABLE%>>"C:\My folder\Myfile.log"
aphoria
  • 19,796
  • 7
  • 64
  • 73
6

I am not proficient at batch scripting but I can tell you that REM stands for Remark. The append won't occur as it is essentially commented out.

http://technet.microsoft.com/en-us/library/bb490986.aspx

Also, the append operator redirects the output of a command to a file. In the snippet you posted it is not clear what output should be redirected.

Eric
  • 133
  • 6
  • well that explains i tryed to record the rem, (im not a bat guy either occasionaly only needing it – Mac Feb 28 '11 at 08:02
5

Any line starting with a "REM" is treated as a comment, nothing is executed including the redirection.

Also, the %date% variable may contain "/" characters which are treated as path separator characters, leading to the system being unable to create the desired log file.

darklion
  • 1,025
  • 7
  • 11