difference b/w %%g and %g% in batch file

May 19, 2009 at 18:03:50
Specs: Windows XP, 2.4 G / 2gb
can any clear me that what the difference b/w
%%g and %g% in batch file

if %%g==

if %g%==

See More: difference b/w %%g and %g% in batch file

Report •

May 20, 2009 at 01:02:43
Some of this information is specific to win nt or higher, but some applies right back to dos:

%%g is a for loop variable only valid inside a for loop, as the for loop iterates over it's set the variable will change accordingly. When the for loop is finished the variable becomes undefined. Also not that in for loop variable are case sensitive and are normally explicitly defined with the exception of a for /f loop where some variables can be implicitly defined.

%g% in an environment variable and can be set using the set command alone, but the /p or /a switches can be present to modify set's behavior. Environment variables set at the command line or is batch file should stay present until the instance of the command processor that created it is closed unless the setlocal command, or one of it's variants, is used. In such a case the variables with either be cleared or restored after the endlocal command. System wide variables are store in the registry and can only be set with utilities, the windows gui or by editing the registry.

Report •

May 20, 2009 at 14:25:06
Thanks A Lot for reply

will you plz help me out for below script

i have prepare a batch script for pinging my all devices.
(in my "ping" file 2 IP is there &

for /f %%I in (ping) do (ping -n 1 %%I | find "Reply" >> nul
if errorlevel 1 echo %%I wan IP was Down >> logfail)
for /f "tokens=1 delims= " %%g in (logfail) do (
if %%g== echo FM02 server is down %time% >> logosspingfail

the output for this script is FM02 server is down,

i want that condition compares two IP and if any one or both IP is not pinging it should show echo ""character"" means
if%%g== or %%g== echo FM02 server is down.

(on applying if condition in 2 lines it showing the message for 2 times that i don't want)

Kindly help me to do so

Report •

May 20, 2009 at 23:20:10
I'm not sure if I follow you correctly, what the below should
do is echo "FM02 server is down %time%" into "logosspingfail"
if either of the addresses fail to reply, but only once if
both of them are inactive.

for /f %%I in (ping) do (
	ping -n 1 %%I | > nul find "Reply" || (
		>> logosspingfail ECHO FM02 server is down %time%

Report •

Related Solutions

May 22, 2009 at 14:14:16
Actually the ping operation is one part of the script, and comparing it with the exact IP and than write the particular character is other.
for /f %%I in (ping) do (ping -n 1 %%I | find "Reply" >> nul
if errorlevel 1 echo %%I wan IP was Down >> logfail)
for /f "tokens=1 delims= " %%g in (logfail) do (
if %%g== echo FM02 server is down >> logosspingfail
if %%g== echo FM01 server is down >> logosspingfail )

@echo off > displayping.html

for /f "tokens=1 delims= " %%g in (logosspingfail) do @ECHO %%g >> displayping.html

goto start

so this is the example what i want,

i am having more that 250 IP so to remember ip on display is typical task, i.e. i want to compare it with ""if "" and than display the character only.

the Problem is - " one device is having 2 IP i want that if any of the IP is down it should display message, both IP down the same message should display."

i think now you are getting me wat exactly i want.

Hope for your response.

thanks for the earlier response


Report •

Ask Question