我正在尝试为此代码创建一个单行输出:
@echo off &SETLOCAL
del Result.txt
echo %date% %time% > Result.txt
FOR /F "tokens=*" %%L IN (hostname.txt) DO (
systeminfo /s %%L|findstr /c:"System Boot Time" /c:"Host Name" >> Result.txt
)
但它是2个衬里。获得单线结果的任何方式?
我希望每个循环的所有输出都在1行
结果应该是:
Wed 01/22/2014 9:32:31.08
Host Name: Test1 System Boot Time: 1/17/2014, 6:41:07 PM
Host Name: Test2 System Boot Time: 1/17/2014, 6:41:57 PM
答案 0 :(得分:1)
@echo off &SETLOCAL EnableDelayedExpansion
set "out="
FOR /F "tokens=*" %%L IN (hostname.txt) DO (
for /F "delims=" %%M in ('systeminfo /s %%L^|findstr /c:"System Boot Time" /c:"Host Name"') do set "out=!out! %%M"
)
echo %date% %time% - %out% > Result.txt
上一批文件使用一行创建Result.txt文件!如果您想要分隔日期和时间的行,请将这些行替换为以下行:
(
echo %date% %time%
echo %out%
) > Result.txt
答案 1 :(得分:0)
@echo off &SETLOCAL
break>Result.txt
echo %date% %time% > Result.txt
FOR /F "tokens=*" %%L IN (hostname.txt) DO (
for /f "delimms=" %%# in ('systeminfo /s %%L^|findstr /c:"System Boot Time" /c:"Host Name" ') do echo|set /p"=%%#">> Result.txt
)
答案 2 :(得分:0)
@echo off
setlocal
(
echo %date% %time%
for /f "tokens=*" %%h in (hostname.txt) do (
wmic /node:%%h os get LastBootUpTime /format:csv 2>nul | findstr /v /r /c:"^Node," /c:"^$"
)
) > result.txt