【问题标题】:How do I make this bat file output the results to a .txt file?如何让这个 bat 文件将结果输出到 .txt 文件?
【发布时间】:2017-09-08 22:49:31
【问题描述】:
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
)

【问题讨论】:

  • 拜托,您能否扩展您对问题的描述以及您的解决方案尝试?谢谢
  • 如何让这个bat文件将结果输出到.txt文件? - 通过使用重定向操作符。
  • @Jay,我已将您的所有代码放入格式化的代码块中,但不清楚您的原始代码是什么样的。您能否检查代码并确认您看到的内容是否与您在脚本中的内容完全相同。

标签: batch-file logging cmd logfile logfiles


【解决方案1】:

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

my.bat >my.txt

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

my.bat >my.bat 2>&1

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

【讨论】:

    猜你喜欢
    • 2018-11-27
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 2011-01-08
    • 2020-06-15
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多