如何使此bat文件将结果输出到.txt文件?

时间:2017-09-08 22:49:31

标签: batch-file logging cmd logfile logfiles

forfiles /p "C:FILEPATH\TO\BE\DELETED\User_1" /s /m *.* /c "cmd /c Del @path" /d -08
forfiles /p "C:FILEPATH\TO\BE\DELETED\User_2" /s /m *.* /c "cmd /c Del @path" /d -08
forfiles /p "C:FILEPATH\TO\BE\DELETED\User_3" /s /m *.* /c "cmd /c Del @path" /d -08
forfiles /p "C:FILEPATH\TO\BE\DELETED\User_4" /s /m *.* /c "cmd /c Del @path" /d -08
forfiles /p "C:FILEPATH\TO\BE\DELETED\User_5" /s /m *.* /c "cmd /c Del @path" /d -08 

@echo off
@echo This purge was successfully completed on the date listed in the file name. 
>purgelog_%date:~-10,2%%date:~-7,2%%date:~-4,4%_.txt 

( command1
  command2
  ...
  commandN
)

1 个答案:

答案 0 :(得分:0)

如果它存储在my.bat中,只需使用重定向。

my.bat >my.txt

如果您还希望stderr进入同一个文件,请使用:

my.bat >my.bat 2>&1

请注意,这不会将purgelog*信息放入my.txt,因为其目标文件已明确指定。