SystemInfo - Get computer System Model via CMD - Extra spaces bug

后端 未结 3 1420
抹茶落季
抹茶落季 2021-01-29 01:17

I\'m trying to get a Computer System Model type via Batch file. for this i\'ve created this script:

systeminfo | find \"System Model\" > %temp%\\TEMPSYSINFO.t         


        
3条回答
  •  灰色年华
    2021-01-29 01:23

    For what it's worth, I tried this and it replaced all double spaces to nothing,
    with echo =%SYSMODEL%= producing :
    =my sysmodel = (just one trailing space) :)

    set SYSMODEL=%SYSMODEL: =%

    EDIT
    So, using Peter's excellent suggestion to put the piped commands into the FOR /F, which I tried that before but came unstuck with a plain | instead of ^| :)

    for /F "tokens=2 delims=:" %%a in ('systeminfo 2^>nul ^| find "System Model"') do set SYSMODEL=%%a
    set SYSMODEL=%SYSMODEL:  =%
    

    EDIT 2
    rojo's answer is great, but it still leaves trailing space for me, so I ended up still using the %var: =% trick

    for /f "tokens=2 delims==" %%a in ('wmic computersystem get model /format:list') do set SYSMODEL=%%a
    set SYSMODEL=%SYSMODEL:  =%
    echo =%SYSMODEL%=
    

提交回复
热议问题