Logic Engine

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Logic Engine

#1 Post by batnoob » 20 Apr 2017 15:25

I am working on a logic engine where you can run normal commands and also call a logic function. first I made an engine it could do the logic just fine, but it couldn't run other commands.

Code: Select all

@echo off
:begin
cls
title Logic engine v1.0
set /p "var=Type logic command>>"
call:LogEn
echo %var%
choice /m "Again?"
IF %ERRORLEVEL% == 1 (GOTO :begin) ELSE (IF %ERRORLEVEL% == 2 (EXIT /B))

:LogEn
if %var% (set "var=True"
) else (set "var=False")
GOTO:EOF

Then I tried to put that in an interactive console as a function and it didn't work anymore

Code: Select all

@echo off
title LIC_v1.0
:1
set /p "command=Type a command>>"
for %%g in (1) do (%command%)
goto :1
exit /b

:Engine arg
@echo off
setlocal
cls
set "var=%1"
call:LogEn
echo %var%
:LogEn
if %var% (set "var=True"
) else (set "var=False")
GOTO:EOF
endlocal
GOTO:EOF

can somebody help with this?

Thanks, BatNoob

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Logic Engine

#2 Post by Compo » 20 Apr 2017 16:21

What are you hoping to achieve with

Code: Select all

if %var% (
IF variable SOMETHING ( you appear to be missing something!

batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Re: Logic Engine

#3 Post by batnoob » 21 Apr 2017 08:41

you would type something like:
1==1
OR
defined %var%

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Logic Engine

#4 Post by aGerman » 21 Apr 2017 09:47

I assume it should be something like that

Code: Select all

@echo off &setlocal

:loop
set /p "comp=Enter a comparison >> "
call :LogEn "%comp%" var
echo %var%
goto :loop
exit /b

:LogEn
if %~1 (set "%~2=True") else set "%~2=False"
exit /b


Example output:

Code: Select all

Enter a comparison >> a==a
True
Enter a comparison >> a==b
False
Enter a comparison >> defined path
True
Enter a comparison >> defined k
False
Enter a comparison >> 1 gtr 2
False
Enter a comparison >> 2 gtr 1
True
Enter a comparison >> exist C:\Windows\
True
Enter a comparison >> exist C:\nothing\
False
Enter a comparison >>

Steffen

Post Reply