Jump to content

DOS Commands


Recommended Posts

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 work

Execute 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 unexpected

Execute the batch file as "renew router" and it releases and renews the connetion and pings the router, then has the goto error

Execute 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


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 :D lol

http://www.msfn.org/board/index.php?showtopic=18349 :rolleyes:

Allanol:

And I thought -I- typed fast :D

Edited by yourtech
Link to comment
Share on other sites

if %1 == router goto :routerif %1 == "" goto :end

should be changed to

if "%1" == "router" goto routerif "%1" == "" goto end

and evenmore change "IF" to "IF /I", so comparison will be caseless :rolleyes:

And furthermore, instead of GOTO, you could use

IF ... (...) ELSE (...)

and

FOR /F ... DO (...)

(See "FOR /?" for documentation :)

EDIT: I remove the ":" before the label

Edited by mdes
Link to comment
Share on other sites

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 :rolleyes:

unfortunately, the batch file still doesn't work trying any of these methods ???

Link to comment
Share on other sites

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 by mdes
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...