简体   繁体   中英

Windows Batch file split string %%i was unexpected at this time

I'm trying to set few variables from systeminfo command in Windows. I read all kinds of similar threads and tried various things, but always keep getting the same error:

%%G was unexpected at this time. 

or

%%i was unexpected at this time.

I've been trying to get this done all day long. Can someone point me in the right direction please? This is what I have tried so far:

for /f "tokens=:" %%i in ('systeminfo ^| grep "OS Name"') do set OSname=%%i

for /f "usebackq delims=: tokens=2" %%i in ('systeminfo ^| grep "OS Name"') do set OSname=%%i

FOR /F "usebackq delims=  tokens=2" %%i IN ('systeminfo ^| grep "OS Name"') DO set vers=%%i


for /f "tokens=* delims= " %%a in ('systeminfo ^|grep "OS Name"') do (set OS_Name=%%a)

systeminfo | find "OS Name" > osname.txt
for /f "usebackq delims=: tokens=2" %%i in (osname.txt) do set osname=%%i


FOR /F %%G IN (FINDSTR /L /C:"OS Name" systeminfo.txt) DO ECHO %%G

UPDATE: I got it to work like this:

FOR /F "usebackq delims=: tokens=2" %i IN (`FINDSTR /L /C:"OS Name" systeminfo.txt`) DO set osname=%i

Any way to remove the leading space in front of the string? Thanks.

这就是获取操作系统名称所需的全部。

 for /f "tokens=2* delims=: " %%i in ('systeminfo ^| find "OS Name"') do set OSname=%%j

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM