bankaifan
Goto Top

Verschachtelte For-Abfrage mit IF

Moin zusammen,

folgendes Problem:

ich hab n kleines Batch-Programm:

for %%i in (0,1,255) do (
for %%j in (0,1,255) do (
for %%k in (0,1,255) do (
ping %%i.%%j.%%k
::Soweit ist alles klar
:: Jetzt möchte ich hier das Errorlevel abfragen und nur bei EL 0 weiter machen, wenn ich aber hier ne IF-Abfrage einbaue sagt er mir Synthaxfehler
set !=
FOR %%h in (0 1 2) do IF Errorlevel %%h00 set EL=%%h
IF not Errorlevel 200 set !=6 7 8 9
FOR %%z in (0 1 2 3 4 5 %!%) do IF Errorlevel %EL%%%z0 set EL=%EL%%%z
IF not Errorlevel 250 set !=6 7 8 9
FOR %%e in (0 1 2 3 4 5 %!%) do IF Errorlevel %EL%%%e set EL=%EL%%%e
ECHO Errorlevel: %EL%
set !=
)
)
)


Wäre schön wenn es doch i-wie gehen würde

Gruß Daniel

Content-Key: 143644

Url: https://administrator.de/contentid/143644

Printed on: April 25, 2024 at 13:04 o'clock

Member: Snowman25
Snowman25 May 27, 2010 at 11:31:13 (UTC)
Goto Top
Hallo @bankaifan,

for %%i in (0,1,255) do (
	for %%j in (0,1,255) do (
		for %%k in (0,1,255) do (
			ping %%i.%%j.%%k
			if ERRORLEVEL 0 (
				set "ding="  
				FOR %%h in (0 1 2) do IF Errorlevel %%h00 set EL=%%h
				IF not Errorlevel 200 set ding=6 7 8 9
				FOR %%z in (0 1 2 3 4 5 %ding%) do IF Errorlevel %EL%%%z0 set EL=%EL%%%z
				IF not Errorlevel 250 set ding=6 7 8 9
				FOR %%e in (0 1 2 3 4 5 %ding%) do IF Errorlevel %EL%%%e set EL=%EL%%%e
				ECHO Errorlevel: %EL%
				set "ding="  
			)
		)
	)
)
man verwendet kein Ausrufezeichen als Variablennamen...
Gruß
Snow

PS: Ich glaube, du möchtest for /L in deinen 3 Schleifen verwenden..
PPS: Seit wann besteht eine IP aus nur 3 Oktetten?
: PPPS : Das ding wird ganz schön lange brauchen...
Member: bankaifan
bankaifan May 27, 2010 at 11:47:16 (UTC)
Goto Top
Danke dir....

scheint zu funktionieren
...

weiß es noch ned ganz sicher, aber sieht gut aus, danke dir

nur noch ne kleine ändernung

if not ERRORLEVEL 1 (
echo %%i.%%j.%%k.0 >> test.txt
)

wenn ich mich nicht irre bedeutet das ja, wenn ERRORLEVEL nicht 1 oder größer
Member: Snowman25
Snowman25 May 27, 2010 at 11:52:56 (UTC)
Goto Top
Zitat von @bankaifan:
wenn ich mich nicht irre bedeutet das ja, wenn ERRORLEVEL nicht 1 oder größer^^
U:\>if /?
Performs conditional processing in batch programs.

IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command

  NOT               Specifies that Windows XP should carry out
                    the command only if the condition is false.

  ERRORLEVEL number Specifies a true condition if the last program run
                    returned an exit code equal to or greater than the number
                    specified.
[...]
%ERRORLEVEL% will expand into a string representation of
the current value of ERRORLEVEL, provided that there is not already
an environment variable with the name ERRORLEVEL, in which case you
will get its value instead.  After running a program, the following
illustrates ERRORLEVEL use:

    goto answer%ERRORLEVEL%
    :answer0
    echo Program had return code 0
    :answer1
    echo Program had return code 1

You can also using the numerical comparisons above:

    IF %ERRORLEVEL% LEQ 1 goto okay
kurz: nö! NOT dreht die Aussage um.
Am besten, du benutzt Errorlevel mit den Vergleichsoperatoren:
    EQU - equal
    NEQ - not equal
    LSS - less than
    LEQ - less than or equal
    GTR - greater than
    GEQ - greater than or equal
So kannst du sicherstellen, dass du auch da landest, wo du hin wolltest
Member: bankaifan
bankaifan May 27, 2010 at 11:54:25 (UTC)
Goto Top
okee^^ jetzt hab ichs verstanden face-smile ... dankö

EDIT: Wenn ich if ERRORLEVEL EQU 0 (...
schreibe sagt er EQU ist synthaktisch an dieser stelle nicht verfügbar/verwendbar
oder muss ich dann dort mit %ERRORLEVEL% EQU 0 machen?
[ot]

*Ne tüte Kaffeebohnen reich*

[/ot]
Member: Snowman25
Snowman25 May 27, 2010 at 11:58:54 (UTC)
Goto Top
Zitat von @bankaifan:
oder muss ich dann dort mit %ERRORLEVEL% EQU 0 machen?
Ja

[ot] *Ne tüte Kaffeebohnen reich* [/ot]
[ot] danke. Jetzt reichts aber auch mit dem rumgespamme von uns face-smile[/ot]
Member: bankaifan
bankaifan May 27, 2010 at 12:00:48 (UTC)
Goto Top
Ok^^

[ot] hast recht [/ot]