[BM]Crusher Posted April 24, 2004 Share Posted April 24, 2004 This is pretty gay and probably out of place on this forum, but hey, I use a lot of DOS batch files during my unattend CD and having a little better knowledge never hurt any one yeah?The thing is, I used to be good with batch files, but since win2k things have worked a little different and now even a simple batch file is almost beyond me!Can someone tell me why the following batch file has the error "goto unexpected at this time" ???I know it is the line "if %1 == "" goto :end" (this sort of syntax worked great under win9x command prompt?)I have tried two other possibilities for that line"if not exists %1 goto :end""if not defined %1 goto :end"neither workExecute the batch file as "renew" and all it does is release and renew like its supposed to simple enough that works but it has the error goto unexpectedExecute the batch file as "renew router" and it releases and renews the connetion and pings the router, then has the goto errorExecute the batch file as "renew router google.com yahoo.com" and it releases/renews the connection, pings the router, pings google and yahoo, then has the goto error and quits...this is the renew.cmd batch file i made to test some basics of batch files@echo off echo Releasing IP Configurationipconfig /release >>null echo Renewing IP Configurationipconfig /renew >>nullecho.echo. :beginif %1 == router goto :routerif %1 == "" goto :end ping %1echo.echo.shiftgoto :begin :routerping 192.168.0.1echo.echo.shiftgoto :begin :endecho.echo.echo All Finishedecho.pause Link to comment Share on other sites More sharing options...
Alanoll Posted April 24, 2004 Share Posted April 24, 2004 i didn't think that with the goto command you needed the :i know with the call command you do, but not goto. You could try call instead. Link to comment Share on other sites More sharing options...
yourtech Posted April 24, 2004 Share Posted April 24, 2004 (edited) Crusher:nope i believe you don't need any colon for a goto. I'd look it up for ya but i lent my mom my dos 6 manual for her to scan the characters codes from lol (she wanted em!!) lol And it is out of place in this forum, you just bumped my -important- topic to 2nd place lolhttp://www.msfn.org/board/index.php?showtopic=18349 Allanol:And I thought -I- typed fast Edited April 24, 2004 by yourtech Link to comment Share on other sites More sharing options...
Frank_Sechrist Posted April 24, 2004 Share Posted April 24, 2004 I think you need to modify the line as follows:if %1.==. goto end Link to comment Share on other sites More sharing options...
mdes Posted April 24, 2004 Share Posted April 24, 2004 (edited) if %1 == router goto :routerif %1 == "" goto :endshould be changed toif "%1" == "router" goto routerif "%1" == "" goto endand evenmore change "IF" to "IF /I", so comparison will be caseless And furthermore, instead of GOTO, you could useIF ... (...) ELSE (...)andFOR /F ... DO (...)(See "FOR /?" for documentation EDIT: I remove the ":" before the label Edited April 25, 2004 by mdes Link to comment Share on other sites More sharing options...
[BM]Crusher Posted April 25, 2004 Author Share Posted April 25, 2004 okies thanks everyone the syntax of the commands have changed since windows 2000 anyone else notice that too? that batch file would have worked a treat on win98 unfortunately, the batch file still doesn't work trying any of these methods ??? Link to comment Share on other sites More sharing options...
mdes Posted April 25, 2004 Share Posted April 25, 2004 (edited) Very strange When removing the SHIFT, the label is found!Here is a solution (without the IPCONFIG; the SET removes the double quotes):SET IP_Router=192.168.0.1 SET IPs=%1SET IPs=%IPs:~1,-1% FOR %%I IN (%IPs%) DO ( IF %%I == router ( PING /n 1 %IP_ROUTER% ) ELSE ( PING /n 1 %%I ))But you should put double quotes around as:renew "www.google.com router www.yahoo.com"and NOT as:renew www.google.com router www.yahoo.com Edited April 25, 2004 by mdes Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now