Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Bjorn94
- Posts: 4
- Joined: 05 Mar 2022 06:35
#1
Post
by Bjorn94 » 05 Mar 2022 06:39
Hi everyone, I have a problem, with this code it should tell me that it is correct, instead it says that it is not, you have to put your processorID inside the quotes, I did not put mine because it would not make sense, someone can tell me why it does not work correctly ?
Code: Select all
@echo off
Set cpuid= wmic cpu get processorid^|more +1
%cpuid%
if NOT "%cpuid%"==" " (goto A) else (goto B)
:B
echo It worked
pause > nul
:A
echo It does not work
pause > nul
Last edited by
aGerman on 05 Mar 2022 09:24, edited 1 time in total.
Reason: Use code formatting!
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 05 Mar 2022 09:23
There is no syntax in batch to just use SET for the assignment of the output of a command. The command has to be executed in a FOR /F loop in order to capture its output. Furthermore, WMIC outputs weird line endings. I'm used to working around it in a second FOR /F.
Code: Select all
@echo off &setlocal
set "cpuid="
for /f "delims=" %%i in ('wmic cpu get ProcessorId /value') do for /f "tokens=2 delims==" %%j in ("%%i") do set "cpuid=%%j"
if not defined cpuid (
echo Unable to get the processor ID
pause
exit /b
)
echo %cpuid%
pause
Steffen