[英]windows 7 not generating txt report
I want to generate a txt file with my dns history. 我想用我的dns历史记录生成一个txt文件。 Although the batch script executes just fine on windows 8, when i run it on windows 7 it simply creates a blank txt file.
尽管批处理脚本在Windows 8上执行得很好,但是当我在Windows 7上运行它时,它只是创建了一个空白的txt文件。 Does anyone knows why this is happening?
有谁知道为什么会这样吗?
Here's the batch script 这是批处理脚本
@echo off
setlocal enableextensions
set "baseName=dnshistory"
set "count=0"
for /f "delims=%baseName%." %%a in (
'dir /b /o-d "%baseName%*.txt" 2^>nul'
) do ( set /a "count=%%a+1" & goto saveData )
:saveData
ipconfig /displaydns | find "Record Name" > "%baseName%%count%.txt"
Is you Windows 7 version in English too ? 您也是英文的Windows 7版本吗?
Open a CMD windows and test just the command : 打开一个CMD窗口并仅测试以下命令:
ipconfig /displaydns | find /i "Record Name"
and look if something is displayed. 看看是否有显示。
If not, try just the command : 如果没有,请尝试以下命令:
ipconfig /displaydns
and look the language used Then correct your code with the correct words. 并查看使用的语言,然后使用正确的单词更正您的代码。
IE in Portuguese it will be : 葡萄牙语的IE将是:
ipconfig /displaydns | find /i "Nome do Registro"
try this for a language independent solution: 尝试以下方法以获得独立于语言的解决方案:
:saveData
(for /f "tokens=2 delims=:" %%a in ('ipconfig /displaydns') do (
echo %%a| find "." |findstr /v /r "[0-9]$"
))>file.txt
(take every line, filter those, that have a .
after a :
(second token) and filter out all lines that end with a number) (将每一行,过滤掉那些在
:
第二个标记)后带有.
行,并过滤掉所有以数字结尾的行)
EDIT another approach (because the above gives some unwanted lines): 编辑另一种方法(因为上面给出了一些不需要的行):
find the first line after every -----------------
line: 在每条
-----------------
行之后找到第一行:
@echo off
setlocal enabledelayedexpansion
ipconfig /displaydns |findstr /n "^" >a.txt
for /f "tokens=1 delims=:" %%a in ('findstr /c:" --------------" a.txt') do (
set /a line=%%a+1
for /f "tokens=1,2,* delims=:" %%i in ('findstr /B "!line!:" a.txt') do echo(%%k
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.