Solved CMD outputs syntax error on if statement

August 30, 2013 at 01:56:44
Specs: Windows 7, 2.4GHz
I am working on an internet browser for a computer inside a game I'm making.
Here's the problem:
CMD outputs an syntax error message when reading the "if" commands, except the top one, which works perfectly.
Also, is there any way to use periods in the comparison string in an if statement? (Example: if %webAdress%==www.google.com goto dostuff)

@Echo off
set dot=.
Echo Initialized...>> "webLog.log"
title Normal Day Simulator v%version% - Internet Browser
cls
if accessedWeb==TRUE (
goto wIndex.end
)
:wIndex.enter_web
cls
Echo Type Exit to exit
set webAdress=0
set /p webAdress="Enter Web Adress: "
if %webAdress%==avg (
cls
title Normal Day Simulator v%version% - Internet Browser - www.google.com
Echo www.google.com>> "webLog.log"
call http_avg
)
if %webAdress%==facebook (
cls
title Normal Day Simulator v%version% - Internet Browser - www.facebook.com
Echo www.facebook.com>> "webLog.log"
call http_facebook
)
if %webAdress%==youtube (
cls
title Normal Day Simulator v%version% - Internet Browser - www.youtube.com
Echo www.youtube.com>> "wIndex\webLog.log"
call http_youtube
)
if %webAdress%==porn (
cls
title Normal Day Simulator v%version% - Internet Browser - www.porn.com
Echo www.porn.com>> "wIndex\webLog.log"
call http_porn
)
if %webAdress%==thepiratebay (
cls
title Normal Day Simulator v%version% - Internet Browser - www.thepiratebay.sx
Echo www.thepiratebay.sx>> "wIndex\webLog.log"
call http_thepiratebay
)
if %webAdress%==wikipedia
cls
title Normal Day Simulator v%version% - Internet Browser - www.wikipedia.org
Echo www.wikipedia.org>> "wIndex\webLog.log"
call http_wikipedia
)
if %webAdress%==microsoft (
cls
title Normal Day Simulator v%version% - Internet Browser - www.microsoft.com
Echo www.microsoft.com>> "wIndex\webLog.log"
call http_microsoft
)
if %webAdress%==retard (
cls
title Normal Day Simulator v%version% - Internet Browser - www.retard.com
Echo www.retard.com>> "wIndex\webLog.log"
call http_retard
)
if %webAdress%==livestream (
cls
title Normal Day Simulator v%version% - Internet Browser - www.livestream.com
Echo www.livestream.com>> "wIndex\webLog.log"
call http_livestream
)
if %webAdress%==googleplus (
cls
title Normal Day Simulator v%version% - Internet Browser - www.plus.google.com
Echo plus.google.com>> "wIndex\webLog.log"
call http_googleplus
)
if %webAdress%==google (
cls
title Normal Day Simulator v%version% - Internet Browser - www.avg.com
Echo www.avg.com>> "wIndex\webLog.log"
call http_google
)
if %webAdress%==0 (
goto wIndex.enter_web
)
cls
goto wIndex.404
:wIndex.404
cls
Echo ERROR 404
Echo.
Echo The page you were looking for could not be found.
Echo Enter the web adress like this: google
Echo.
Echo.
Echo ***Press any key to return***
pause > nul
goto wIndex.enter_web

message edited by RainBawZ


See More: CMD outputs syntax error on if statement

Report •

#1
August 30, 2013 at 08:19:21
So many mistakes here.
Why are you setting the dot as a variable? You don't need to.
if accessedWeb==TRUE (
goto wIndex.end
)

you don't need the brackets, just make it:
if accessedWeb==TRUE goto wIndex.end
set webaddress==0. Why? if you have never even called that variable why would it even contain anything? if you have just type set webaddress=.
The if statements aren't what's making your code to be invalid.
You need to remember to escape.
So change > to ^> every time you set it as a title, there is no other explanation, your %version% variable contains some special symbols.

message edited by ksas


Report •

#2
August 30, 2013 at 13:10:59
This script is called by "main" script, which sets a few variables before calling the script, as for the brackets, I use them to make the script less messy. Just ignore the dot variable, I created it to check if it would do any difference when using periods in an if statement.

Set webAdress=0 is for preventing the program to crash if no input is provided at the set /p command.

%Version% only contains this type of stuff: 0.0.4.5 (the Version of the script)

message edited by RainBawZ


Report •

#3
August 30, 2013 at 19:26:59
✔ Best Answer
You left out the leading parenthesee on your test for wikipedia. Also, as ksas pointed out, the code could be improved to be shorter, faster, and more efficient. But, (other than this version), i'm not going there. It might work with the aforementioned fix.
:: attempt at optimizing code
@Echo off
set titl=Normal Day Simulator v%version% - Internet browser
Echo Initialized...>> "webLog.log"
title %titl%
cls
if accessedWeb==TRUE (
goto wIndex.end
)
:wIndex.enter_web
cls
Echo Type Exit to exit
set webAdress=
set /p webAdress="Enter Web Adress: "
if /i %webadress% equ exit goto :eof
if not defined webadress goto :windex.enter_web
call :%webadress% %webadress%|| goto :windex.404
goto :windex.enter_web

:avg
call :init %1
:: do whatever here
goto :eof

:facebook
call :init %1
:: do whatever here
goto :eof

:etc etc...
::===============
:init
cls
set url=www.%1.com
title %titl% - %url%
Echo %url%>> "webLog.log"
echo %url%.....
pause
goto :eof

:wIndex.404
cls
Echo ERROR 404
Echo.
Echo The page you were looking for could not be found.
Echo Enter the web adress like this: google
Echo.
Echo.
Echo ***Press any key to return***
pause > nul
goto wIndex.enter_web

message edited by nbrane


Report •

Related Solutions

#4
August 31, 2013 at 07:31:24
This seems to work, thanks.

Report •

Ask Question