登录批处理文件 [英] Logging In Batch Files

查看:88
本文介绍了登录批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我制作了一个批处理文件,将所有内容记录到txt文件中,但我希望每次记录时都将其覆盖,而不仅仅是添加到日志文件中已存在的内容中.

这是到目前为止我的批处理文件中的内容:

Hi, I made a batch file that logs everything to a txt file, but I want it to OVERWRITE every time it logs, instead of just adding to what is already in the log file.

Here is what I have so far in my batch file:

@Echo Off
Echo "Important!: Leave this window open until scan is finished"
SetLocal EnableDelayedExpansion
Set _Start=20
Set _End=23
Set _NoPings=1
Set _Site=192.168.1.1
Set _Found=%~dp0Portfound.txt
Set _Log=%~dp0Portlog.txt
Del "%_Log%"
For /L %%I In (%_start%,1,%_End%) Do (
Echo Testing port %%I >>"%_log%"
  >Nul 2>&1 tcping -n %_NoPings% %_Site% %%I
  If !ErrorLevel!==0 (
    >>"%_Found%" Echo "Success! Port %%I is open"
  ) Else (
    >>"%_Log%" Echo "Port %%I is not open"
  ))



该批处理文件将日志记录在原应的位置,但是我希望它覆盖日志文件中的所有内容,而不是添加到该文件中.

有任何想法吗?



This batch file logs where it is supposed to, but I want it to overwrite everything in the log file, instead of adding to it.

Any Ideas?

推荐答案

行后:
Del "%_Log%"



您应该添加带有单个>符号的行,该行将开始写入新文件,因此:



You should add a line with a single > sign which will start writing a new file, thus:

Del "%_Log%"
Echo "Starting" > "%_Log%"
...
 remaining output using double <code>>></code> signs.
...


这篇关于登录批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆