@echo off
set a=2,113 MB
for /f "tokens=2* delims=:" %%a in ('systeminfo ^| findstr /I /C:"Total Physical Memory"') do set r=%%a
echo available RAM IS %r%
pause
if "%r%" gtr "%a%"
(
echo "proceed"
)
else (
echo "no"
)
pause
Asked
Active
Viewed 90 times
-2

Melebius
- 6,183
- 4
- 39
- 52
-
1What is the expected and actual output? – Melebius Nov 29 '17 at 09:54
-
They syntax you are using for the IF command is incorrect. Open up a command prompt and type: `if /?` Also, you need to understand that all variables in batch files are strings unless comparing integers which you are not. You are still trying to compare strings because you values are not pure integers and you are using quotes with your comparison. – Squashman Nov 29 '17 at 15:16
-
@MahaLakshmi Please read the answer on [Symbol equivalent to NEQ, LSS, GTR, etc. in Windows batch files](https://stackoverflow.com/a/47386323/3074564) for an explanation why you compare left __string__ being greater than right __string__ instead of comparing if left __integer__ is greater than right __integer__. And read the answer on [IF ELSE syntax error within batch file?](https://stackoverflow.com/a/25471786/3074564) as well as [this answer](https://stackoverflow.com/a/34118487/3074564) for the right syntax of an __IF__ condition in a batch file. – Mofi Dec 01 '17 at 16:15
1 Answers
0
This is just another way to check ram do the required if
conditions
are met.
@echo off
::set required memory size 1024=1GB | 2048=2GB | 3072=3GB | 4096=4GB ||
set reqramsize=1024
for /f "tokens=4" %%a in ('systeminfo ^| findstr Physical') do if defined totalMem (set availableMem=%%a) else (set totalMem=%%a)
set totalMem=%totalMem:,=%
set availableMem=%availableMem:,=%
set /a usedMem=totalMem-availableMem
:: Output Your Memory Variables
echo Total Memory: %totalMem%
echo Used Memory: %usedMem%
::Check Condition with Used Memory & Required Memory
if %usedMem% GTR %reqramsize% (goto available) else goto navailable
:available
echo ram available - Proceed
pause>nul
:navailable
echo ram not available - Unable to Proceed
pause>nul
exit

Gourav
- 116
- 1
- 6
-
this doesn't answer the question because it doesn't explain why the OP's code behave that way – phuclv Nov 30 '17 at 02:43