Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
733 views
in Technique[技术] by (71.8m points)

batch file - Append text with .bat

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:"VTSADVANCED TOOLSSYSTEMLOGAdvanced tools %date%.log"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 folderMyfile.log"

Append a blank line to a file:

ECHO.>>"C:My folderMyfile.log"

Append text to a file:

ECHO Some text>>"C:My folderMyfile.log"

Append a variable to a file:

ECHO %MY_VARIABLE%>>"C:My folderMyfile.log"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...