سؤال

I'm trying to create a one liner output for this code:

@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

)

but it's on 2 liners. Any way of getting a one liner result?

I would like all output on 1 line for each loop

Results should be like:

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
هل كانت مفيدة؟

المحلول

@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

Previous Batch file create Result.txt file with one line! If you want separated lines for the date and time, replace last line by these ones:

(
echo %date% %time%
echo %out%
) > Result.txt

نصائح أخرى

@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

)
@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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top