Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: ERRORLEVEL

HTVi
TV Discussion Newsgroups

ERRORLEVEL
Jmnts 10/18/2008 2:52:01 PM
Hi everyone

I'm trying to do errorlevel handling but not with expected results:
Code:

Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
IF NOT ERRORLEVEL 0 (
Echo. Connection Failed for to %%a
Echo. Connection Failed for to %%a >>Log.txt
) Else (
Echo. Connected to %%a
Echo. Connected to %%a >>Log.txt
)


The problem is that always "Echo. Connected to %%a" not matter if it fails
or not, the result is always the saame. Can anyone help me?
Re: ERRORLEVEL
"Pegasus \(MVP\)" <I.can[ at ]fly.com.oz> 10/18/2008 3:24:50 PM

"Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
[Quoted Text]
> Hi everyone
>
> I'm trying to do errorlevel handling but not with expected results:
> Code:
>
> Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> IF NOT ERRORLEVEL 0 (
> Echo. Connection Failed for to %%a
> Echo. Connection Failed for to %%a >>Log.txt
> ) Else (
> Echo. Connected to %%a
> Echo. Connected to %%a >>Log.txt
> )
>
>
> The problem is that always "Echo. Connected to %%a" not matter if it fails
> or not, the result is always the saame. Can anyone help me?

I hate double inverted logic. It goes against human thinking. Why not keep
things simple and use direct logic, e.g. like so:
Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
if %ErrorLevel% EQU 0 (
Echo Connected to %%a
Echo Connected to %%a >>Log.txt
) Else (
Echo Connection Failed for to %%a
Echo Connection Failed for to %%a >>Log.txt
)

Note the changed syntax: In the above code "ErrorLevel" is an environmental
variable and "EQU" must be in caps.


Re: ERRORLEVEL
Jmnts 10/18/2008 5:02:01 PM
Hi Pegasus and thank you for your time
Using the commands on one batch works fine, but when I add them to the batch
its stops working??
Perhaps you can help me if I put the entire script.
This is working for successful connections, but when the connection fails or
bad username the log is recorded as success "Connected to..."??!!

Begin---------------------
cls
net use * /d /y

Echo. Begin >log.txt
Echo. |date /T >>log.txt
Echo. |time /T >>log.txt
Echo. >>log.txt

For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
Echo Username Password ServerIP
Echo %%a %%b %%c

Net use \\%%c %%b /User:%%a

if %ErrorLevel% EQU 0 (
Echo Connected to %%c >>log.txt
Echo Connected to %%c
) Else (
Echo Connection Failed for to %%c >>log.txt
Echo Connection Failed for to %%c
)
)
End Batch ---------------------

Thank you

"Pegasus (MVP)" wrote:

[Quoted Text]
>
> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
> > Hi everyone
> >
> > I'm trying to do errorlevel handling but not with expected results:
> > Code:
> >
> > Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> > IF NOT ERRORLEVEL 0 (
> > Echo. Connection Failed for to %%a
> > Echo. Connection Failed for to %%a >>Log.txt
> > ) Else (
> > Echo. Connected to %%a
> > Echo. Connected to %%a >>Log.txt
> > )
> >
> >
> > The problem is that always "Echo. Connected to %%a" not matter if it fails
> > or not, the result is always the saame. Can anyone help me?
>
> I hate double inverted logic. It goes against human thinking. Why not keep
> things simple and use direct logic, e.g. like so:
> Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> if %ErrorLevel% EQU 0 (
> Echo Connected to %%a
> Echo Connected to %%a >>Log.txt
> ) Else (
> Echo Connection Failed for to %%a
> Echo Connection Failed for to %%a >>Log.txt
> )
>
> Note the changed syntax: In the above code "ErrorLevel" is an environmental
> variable and "EQU" must be in caps.
>
>
>
Re: ERRORLEVEL
"Al Dunbar" <AlanDrub[ at ]hotmail.com.nospaam> 10/18/2008 8:37:31 PM

"Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
[Quoted Text]
> Hi everyone
>
> I'm trying to do errorlevel handling but not with expected results:
> Code:
>
> Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> IF NOT ERRORLEVEL 0 (
> Echo. Connection Failed for to %%a
> Echo. Connection Failed for to %%a >>Log.txt
> ) Else (
> Echo. Connected to %%a
> Echo. Connected to %%a >>Log.txt
> )
>
>
> The problem is that always "Echo. Connected to %%a" not matter if it fails
> or not, the result is always the saame. Can anyone help me?

1) IF ERRORLEVEL 3: this returns a true value if the errorlevel is 3 or
greater

2) IF ERRORLEVEL 0: this returns a true value if the errorlevel is 0 or
greater. It is therefore always true, unless a negative errorlevel is
possible.

2) IF NOT ERRORLEVEL 0: this returns a false value if the errorlevel is 0 or
greater. It is therefore always false, unless a negative errorlevel is
possible.

This has been the case since the old DOS days. A more workable version of
your code above would be:

> IF ERRORLEVEL 1 (
> Echo. Connection Failed for to %%a
> Echo. Connection Failed for to %%a >>Log.txt
> ) Else (
> Echo. Connected to %%a
> Echo. Connected to %%a >>Log.txt
> )

/Al


Re: ERRORLEVEL
"Al Dunbar" <AlanDrub[ at ]hotmail.com.nospaam> 10/18/2008 8:45:58 PM

"Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
news:5AF5BF0A-2C87-4A6A-8D60-7A62B0EB346B[ at ]microsoft.com...
[Quoted Text]
> Hi Pegasus and thank you for your time
> Using the commands on one batch works fine, but when I add them to the
> batch
> its stops working??

Note that commands may not always return what you might expect as the
errorlevel. You sometimes have to find other means to verify the success or
failure of the command being tested. For example, if the operation is to
delete a file, then you could test afterwards for its existence.

> Perhaps you can help me if I put the entire script.
> This is working for successful connections, but when the connection fails
> or
> bad username the log is recorded as success "Connected to..."??!!
>
> Begin---------------------
> cls
> net use * /d /y
>
> Echo. Begin >log.txt
> Echo. |date /T >>log.txt
> Echo. |time /T >>log.txt
> Echo. >>log.txt

As an aside, I'd suggest doing this a bit differently:

(
Echo/ Begin
Echo/ %date%
Echo/ %time%
Echo/
) >log.txt

Using the DATE and TIME variables instead of the commands will allow them to
appear on the same line:

(
Echo/ Begin at %time% on %date%
Echo/
) >log.txt

Also, "echo/" is marginally better than "echo.", however I can't quite
remember why...

> For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> Echo Username Password ServerIP
> Echo %%a %%b %%c
>
> Net use \\%%c %%b /User:%%a
>
> if %ErrorLevel% EQU 0 (
> Echo Connected to %%c >>log.txt
> Echo Connected to %%c
> ) Else (
> Echo Connection Failed for to %%c >>log.txt
> Echo Connection Failed for to %%c
> )
> )
> End Batch ---------------------
>
> Thank you
>
> "Pegasus (MVP)" wrote:
>
>>
>> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
>> > Hi everyone
>> >
>> > I'm trying to do errorlevel handling but not with expected results:
>> > Code:
>> >
>> > Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
>> > IF NOT ERRORLEVEL 0 (
>> > Echo. Connection Failed for to %%a
>> > Echo. Connection Failed for to %%a >>Log.txt
>> > ) Else (
>> > Echo. Connected to %%a
>> > Echo. Connected to %%a >>Log.txt
>> > )
>> >
>> >
>> > The problem is that always "Echo. Connected to %%a" not matter if it
>> > fails
>> > or not, the result is always the saame. Can anyone help me?
>>
>> I hate double inverted logic. It goes against human thinking. Why not
>> keep
>> things simple and use direct logic, e.g. like so:
>> Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
>> if %ErrorLevel% EQU 0 (
>> Echo Connected to %%a
>> Echo Connected to %%a >>Log.txt
>> ) Else (
>> Echo Connection Failed for to %%a
>> Echo Connection Failed for to %%a >>Log.txt
>> )
>>
>> Note the changed syntax: In the above code "ErrorLevel" is an
>> environmental
>> variable and "EQU" must be in caps.
>>
>>
>>


Re: ERRORLEVEL
Jmnts 10/18/2008 10:24:01 PM
Hi again and thank you all for you answers. Not sure why but I found out that
the problem is that the %errorlevel% doesn't seemed to work (always returns
the same code error) in the For condition. However if I don't use the For
condition works pretty well!!! So I'm going to share the answer that I found.
Basically I create a temporary file and check the results on that file:

Begin---------------------
cls
net use * /d /y

Echo. Begin >log.txt
Echo. |date /T >>log.txt
Echo. |time /T >>log.txt
Echo. >>log.txt

For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
Echo Username Password ServerIP
Echo %%a %%b %%c

Net use \\%%c %%b /User:%%a>tmp.txt
Find "The command completed successfully" < tmp.txt > nul
IF NOT ERRORLEVEL 1 (
Echo Connected to %%c >>log.txt
Echo Connected to %%c
) Else (
Echo Connection Failed for to %%c >>Log.txt
Echo Connection Failed for to %%c
)
del tmp.txt
)
End Batch ---------------------

For now is working :)

Another question... I started this batch file from another one that I found
in the net. The sample was something like this

For /f "tokens=1" %%a in (C:\mytextfile.txt) do (
If /i "%%a" NEQ "All" (
etc... etc...

this batch sample was reading servernames from mytextfile.txt and transfer
files to those servers.

What I don't full understand is the line "If /i "%%a" NEQ "All" ( "
okay:
"If" is the condition
"/i" - Not sure what it means in this context
"%%a" is variable that represents the "tokens=1"
"NEQ" Not equal
"All" - What is this? Is it trying to get something different from All???!!


Thank you all.




"Al Dunbar" wrote:

[Quoted Text]
>
> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> news:5AF5BF0A-2C87-4A6A-8D60-7A62B0EB346B[ at ]microsoft.com...
> > Hi Pegasus and thank you for your time
> > Using the commands on one batch works fine, but when I add them to the
> > batch
> > its stops working??
>
> Note that commands may not always return what you might expect as the
> errorlevel. You sometimes have to find other means to verify the success or
> failure of the command being tested. For example, if the operation is to
> delete a file, then you could test afterwards for its existence.
>
> > Perhaps you can help me if I put the entire script.
> > This is working for successful connections, but when the connection fails
> > or
> > bad username the log is recorded as success "Connected to..."??!!
> >
> > Begin---------------------
> > cls
> > net use * /d /y
> >
> > Echo. Begin >log.txt
> > Echo. |date /T >>log.txt
> > Echo. |time /T >>log.txt
> > Echo. >>log.txt
>
> As an aside, I'd suggest doing this a bit differently:
>
> (
> Echo/ Begin
> Echo/ %date%
> Echo/ %time%
> Echo/
> ) >log.txt
>
> Using the DATE and TIME variables instead of the commands will allow them to
> appear on the same line:
>
> (
> Echo/ Begin at %time% on %date%
> Echo/
> ) >log.txt
>
> Also, "echo/" is marginally better than "echo.", however I can't quite
> remember why...
>
> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> > Echo Username Password ServerIP
> > Echo %%a %%b %%c
> >
> > Net use \\%%c %%b /User:%%a
> >
> > if %ErrorLevel% EQU 0 (
> > Echo Connected to %%c >>log.txt
> > Echo Connected to %%c
> > ) Else (
> > Echo Connection Failed for to %%c >>log.txt
> > Echo Connection Failed for to %%c
> > )
> > )
> > End Batch ---------------------
> >
> > Thank you
> >
> > "Pegasus (MVP)" wrote:
> >
> >>
> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
> >> > Hi everyone
> >> >
> >> > I'm trying to do errorlevel handling but not with expected results:
> >> > Code:
> >> >
> >> > Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> >> > IF NOT ERRORLEVEL 0 (
> >> > Echo. Connection Failed for to %%a
> >> > Echo. Connection Failed for to %%a >>Log.txt
> >> > ) Else (
> >> > Echo. Connected to %%a
> >> > Echo. Connected to %%a >>Log.txt
> >> > )
> >> >
> >> >
> >> > The problem is that always "Echo. Connected to %%a" not matter if it
> >> > fails
> >> > or not, the result is always the saame. Can anyone help me?
> >>
> >> I hate double inverted logic. It goes against human thinking. Why not
> >> keep
> >> things simple and use direct logic, e.g. like so:
> >> Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> >> if %ErrorLevel% EQU 0 (
> >> Echo Connected to %%a
> >> Echo Connected to %%a >>Log.txt
> >> ) Else (
> >> Echo Connection Failed for to %%a
> >> Echo Connection Failed for to %%a >>Log.txt
> >> )
> >>
> >> Note the changed syntax: In the above code "ErrorLevel" is an
> >> environmental
> >> variable and "EQU" must be in caps.
> >>
> >>
> >>
>
>
>
Re: ERRORLEVEL
"Al Dunbar" <AlanDrub[ at ]hotmail.com.nospaam> 10/19/2008 12:54:01 AM
Sorry, it didn't hit me until I read your last reply, but you the
%errorlevel% appears within a compound statement.

As is the case with a simple statement, the statement is read in, the
environment %variable% references are expanded, and only then the command
starts executing. The upshot is that any variable references for all of the
statements in a compound statement are expanded before the first statement
is executed. And this will be before the execution of any statement that is
likely to modify the variables involved. Here is a test script you can run
to demonstrate this for yourself:

[ at ]echo off

setlocal enabledelayedexpansion

echo/%date% | find "0"
echo/%errorlevel%
echo/%date% | find "XX"
echo/%errorlevel%

for /l %%F in (1,1,1) do (
echo/%date% | find "0"
echo/%errorlevel%
echo/%date% | find "XX"
echo/%errorlevel%
)

for /l %%F in (1,1,1) do (
echo/%date% | find "0"
echo/!errorlevel!
echo/%date% | find "XX"
echo/!errorlevel!
)

pause

in each set of commands, the errorlevel value is zero and then some non-zero
value. This is accurately displayed in the first set of commands as they are
not contained within parentheses. In the second, the values displayed are 1
and 1. These are the values the variable had just before the for loop.

In the last for loop, the errorlevel values are displayed correctly because
the setlocal command enabled delayed expansion, and because "!" was used
instead of "%".

This is a common issue that catches just about everyone at one time or
another because it seems so counter intuitive.


/Al


"Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
news:54108A13-F744-4B5F-8709-DC64EA75B507[ at ]microsoft.com...
[Quoted Text]
> Hi again and thank you all for you answers. Not sure why but I found out
> that
> the problem is that the %errorlevel% doesn't seemed to work (always
> returns
> the same code error) in the For condition. However if I don't use the For
> condition works pretty well!!! So I'm going to share the answer that I
> found.
> Basically I create a temporary file and check the results on that file:
>
> Begin---------------------
> cls
> net use * /d /y
>
> Echo. Begin >log.txt
> Echo. |date /T >>log.txt
> Echo. |time /T >>log.txt
> Echo. >>log.txt
>
> For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> Echo Username Password ServerIP
> Echo %%a %%b %%c
>
> Net use \\%%c %%b /User:%%a>tmp.txt
> Find "The command completed successfully" < tmp.txt > nul
> IF NOT ERRORLEVEL 1 (
> Echo Connected to %%c >>log.txt
> Echo Connected to %%c
> ) Else (
> Echo Connection Failed for to %%c >>Log.txt
> Echo Connection Failed for to %%c
> )
> del tmp.txt
> )
> End Batch ---------------------
>
> For now is working :)
>
> Another question... I started this batch file from another one that I
> found
> in the net. The sample was something like this
>
> For /f "tokens=1" %%a in (C:\mytextfile.txt) do (
> If /i "%%a" NEQ "All" (
> etc... etc...
>
> this batch sample was reading servernames from mytextfile.txt and transfer
> files to those servers.
>
> What I don't full understand is the line "If /i "%%a" NEQ "All" ( "
> okay:
> "If" is the condition
> "/i" - Not sure what it means in this context
> "%%a" is variable that represents the "tokens=1"
> "NEQ" Not equal
> "All" - What is this? Is it trying to get something different from
> All???!!
>
>
> Thank you all.
>
>
>
>
> "Al Dunbar" wrote:
>
>>
>> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> news:5AF5BF0A-2C87-4A6A-8D60-7A62B0EB346B[ at ]microsoft.com...
>> > Hi Pegasus and thank you for your time
>> > Using the commands on one batch works fine, but when I add them to the
>> > batch
>> > its stops working??
>>
>> Note that commands may not always return what you might expect as the
>> errorlevel. You sometimes have to find other means to verify the success
>> or
>> failure of the command being tested. For example, if the operation is to
>> delete a file, then you could test afterwards for its existence.
>>
>> > Perhaps you can help me if I put the entire script.
>> > This is working for successful connections, but when the connection
>> > fails
>> > or
>> > bad username the log is recorded as success "Connected to..."??!!
>> >
>> > Begin---------------------
>> > cls
>> > net use * /d /y
>> >
>> > Echo. Begin >log.txt
>> > Echo. |date /T >>log.txt
>> > Echo. |time /T >>log.txt
>> > Echo. >>log.txt
>>
>> As an aside, I'd suggest doing this a bit differently:
>>
>> (
>> Echo/ Begin
>> Echo/ %date%
>> Echo/ %time%
>> Echo/
>> ) >log.txt
>>
>> Using the DATE and TIME variables instead of the commands will allow them
>> to
>> appear on the same line:
>>
>> (
>> Echo/ Begin at %time% on %date%
>> Echo/
>> ) >log.txt
>>
>> Also, "echo/" is marginally better than "echo.", however I can't quite
>> remember why...
>>
>> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
>> > Echo Username Password ServerIP
>> > Echo %%a %%b %%c
>> >
>> > Net use \\%%c %%b /User:%%a
>> >
>> > if %ErrorLevel% EQU 0 (
>> > Echo Connected to %%c >>log.txt
>> > Echo Connected to %%c
>> > ) Else (
>> > Echo Connection Failed for to %%c >>log.txt
>> > Echo Connection Failed for to %%c
>> > )
>> > )
>> > End Batch ---------------------
>> >
>> > Thank you
>> >
>> > "Pegasus (MVP)" wrote:
>> >
>> >>
>> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> >> news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
>> >> > Hi everyone
>> >> >
>> >> > I'm trying to do errorlevel handling but not with expected results:
>> >> > Code:
>> >> >
>> >> > Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
>> >> > IF NOT ERRORLEVEL 0 (
>> >> > Echo. Connection Failed for to %%a
>> >> > Echo. Connection Failed for to %%a >>Log.txt
>> >> > ) Else (
>> >> > Echo. Connected to %%a
>> >> > Echo. Connected to %%a >>Log.txt
>> >> > )
>> >> >
>> >> >
>> >> > The problem is that always "Echo. Connected to %%a" not matter if it
>> >> > fails
>> >> > or not, the result is always the saame. Can anyone help me?
>> >>
>> >> I hate double inverted logic. It goes against human thinking. Why not
>> >> keep
>> >> things simple and use direct logic, e.g. like so:
>> >> Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
>> >> if %ErrorLevel% EQU 0 (
>> >> Echo Connected to %%a
>> >> Echo Connected to %%a >>Log.txt
>> >> ) Else (
>> >> Echo Connection Failed for to %%a
>> >> Echo Connection Failed for to %%a >>Log.txt
>> >> )
>> >>
>> >> Note the changed syntax: In the above code "ErrorLevel" is an
>> >> environmental
>> >> variable and "EQU" must be in caps.
>> >>
>> >>
>> >>
>>
>>
>>


Re: ERRORLEVEL
Jmnts 10/19/2008 4:33:01 PM
Thank you, I'll give it a try latter, but sounds convincent. What about the
"If /i "%%a" NEQ "All" ( " Thing?
Can you explain that?

Thank you again for your time guys.

"Al Dunbar" wrote:

[Quoted Text]
> Sorry, it didn't hit me until I read your last reply, but you the
> %errorlevel% appears within a compound statement.
>
> As is the case with a simple statement, the statement is read in, the
> environment %variable% references are expanded, and only then the command
> starts executing. The upshot is that any variable references for all of the
> statements in a compound statement are expanded before the first statement
> is executed. And this will be before the execution of any statement that is
> likely to modify the variables involved. Here is a test script you can run
> to demonstrate this for yourself:
>
> [ at ]echo off
>
> setlocal enabledelayedexpansion
>
> echo/%date% | find "0"
> echo/%errorlevel%
> echo/%date% | find "XX"
> echo/%errorlevel%
>
> for /l %%F in (1,1,1) do (
> echo/%date% | find "0"
> echo/%errorlevel%
> echo/%date% | find "XX"
> echo/%errorlevel%
> )
>
> for /l %%F in (1,1,1) do (
> echo/%date% | find "0"
> echo/!errorlevel!
> echo/%date% | find "XX"
> echo/!errorlevel!
> )
>
> pause
>
> in each set of commands, the errorlevel value is zero and then some non-zero
> value. This is accurately displayed in the first set of commands as they are
> not contained within parentheses. In the second, the values displayed are 1
> and 1. These are the values the variable had just before the for loop.
>
> In the last for loop, the errorlevel values are displayed correctly because
> the setlocal command enabled delayed expansion, and because "!" was used
> instead of "%".
>
> This is a common issue that catches just about everyone at one time or
> another because it seems so counter intuitive.
>
>
> /Al
>
>
> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> news:54108A13-F744-4B5F-8709-DC64EA75B507[ at ]microsoft.com...
> > Hi again and thank you all for you answers. Not sure why but I found out
> > that
> > the problem is that the %errorlevel% doesn't seemed to work (always
> > returns
> > the same code error) in the For condition. However if I don't use the For
> > condition works pretty well!!! So I'm going to share the answer that I
> > found.
> > Basically I create a temporary file and check the results on that file:
> >
> > Begin---------------------
> > cls
> > net use * /d /y
> >
> > Echo. Begin >log.txt
> > Echo. |date /T >>log.txt
> > Echo. |time /T >>log.txt
> > Echo. >>log.txt
> >
> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> > Echo Username Password ServerIP
> > Echo %%a %%b %%c
> >
> > Net use \\%%c %%b /User:%%a>tmp.txt
> > Find "The command completed successfully" < tmp.txt > nul
> > IF NOT ERRORLEVEL 1 (
> > Echo Connected to %%c >>log.txt
> > Echo Connected to %%c
> > ) Else (
> > Echo Connection Failed for to %%c >>Log.txt
> > Echo Connection Failed for to %%c
> > )
> > del tmp.txt
> > )
> > End Batch ---------------------
> >
> > For now is working :)
> >
> > Another question... I started this batch file from another one that I
> > found
> > in the net. The sample was something like this
> >
> > For /f "tokens=1" %%a in (C:\mytextfile.txt) do (
> > If /i "%%a" NEQ "All" (
> > etc... etc...
> >
> > this batch sample was reading servernames from mytextfile.txt and transfer
> > files to those servers.
> >
> > What I don't full understand is the line "If /i "%%a" NEQ "All" ( "
> > okay:
> > "If" is the condition
> > "/i" - Not sure what it means in this context
> > "%%a" is variable that represents the "tokens=1"
> > "NEQ" Not equal
> > "All" - What is this? Is it trying to get something different from
> > All???!!
> >
> >
> > Thank you all.
> >
> >
> >
> >
> > "Al Dunbar" wrote:
> >
> >>
> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> news:5AF5BF0A-2C87-4A6A-8D60-7A62B0EB346B[ at ]microsoft.com...
> >> > Hi Pegasus and thank you for your time
> >> > Using the commands on one batch works fine, but when I add them to the
> >> > batch
> >> > its stops working??
> >>
> >> Note that commands may not always return what you might expect as the
> >> errorlevel. You sometimes have to find other means to verify the success
> >> or
> >> failure of the command being tested. For example, if the operation is to
> >> delete a file, then you could test afterwards for its existence.
> >>
> >> > Perhaps you can help me if I put the entire script.
> >> > This is working for successful connections, but when the connection
> >> > fails
> >> > or
> >> > bad username the log is recorded as success "Connected to..."??!!
> >> >
> >> > Begin---------------------
> >> > cls
> >> > net use * /d /y
> >> >
> >> > Echo. Begin >log.txt
> >> > Echo. |date /T >>log.txt
> >> > Echo. |time /T >>log.txt
> >> > Echo. >>log.txt
> >>
> >> As an aside, I'd suggest doing this a bit differently:
> >>
> >> (
> >> Echo/ Begin
> >> Echo/ %date%
> >> Echo/ %time%
> >> Echo/
> >> ) >log.txt
> >>
> >> Using the DATE and TIME variables instead of the commands will allow them
> >> to
> >> appear on the same line:
> >>
> >> (
> >> Echo/ Begin at %time% on %date%
> >> Echo/
> >> ) >log.txt
> >>
> >> Also, "echo/" is marginally better than "echo.", however I can't quite
> >> remember why...
> >>
> >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> >> > Echo Username Password ServerIP
> >> > Echo %%a %%b %%c
> >> >
> >> > Net use \\%%c %%b /User:%%a
> >> >
> >> > if %ErrorLevel% EQU 0 (
> >> > Echo Connected to %%c >>log.txt
> >> > Echo Connected to %%c
> >> > ) Else (
> >> > Echo Connection Failed for to %%c >>log.txt
> >> > Echo Connection Failed for to %%c
> >> > )
> >> > )
> >> > End Batch ---------------------
> >> >
> >> > Thank you
> >> >
> >> > "Pegasus (MVP)" wrote:
> >> >
> >> >>
> >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> >> news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
> >> >> > Hi everyone
> >> >> >
> >> >> > I'm trying to do errorlevel handling but not with expected results:
> >> >> > Code:
> >> >> >
> >> >> > Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> >> >> > IF NOT ERRORLEVEL 0 (
> >> >> > Echo. Connection Failed for to %%a
> >> >> > Echo. Connection Failed for to %%a >>Log.txt
> >> >> > ) Else (
> >> >> > Echo. Connected to %%a
> >> >> > Echo. Connected to %%a >>Log.txt
> >> >> > )
> >> >> >
> >> >> >
> >> >> > The problem is that always "Echo. Connected to %%a" not matter if it
> >> >> > fails
> >> >> > or not, the result is always the saame. Can anyone help me?
> >> >>
> >> >> I hate double inverted logic. It goes against human thinking. Why not
> >> >> keep
> >> >> things simple and use direct logic, e.g. like so:
> >> >> Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> >> >> if %ErrorLevel% EQU 0 (
> >> >> Echo Connected to %%a
> >> >> Echo Connected to %%a >>Log.txt
> >> >> ) Else (
> >> >> Echo Connection Failed for to %%a
> >> >> Echo Connection Failed for to %%a >>Log.txt
> >> >> )
> >> >>
> >> >> Note the changed syntax: In the above code "ErrorLevel" is an
> >> >> environmental
> >> >> variable and "EQU" must be in caps.
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
Re: ERRORLEVEL
"Pegasus \(MVP\)" <I.can[ at ]fly.com.oz> 10/19/2008 5:39:51 PM

"Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
news:DE799BDB-C403-41C1-AF51-C4A6CD728345[ at ]microsoft.com...
[Quoted Text]
> Thank you, I'll give it a try latter, but sounds convincent. What about
> the
> "If /i "%%a" NEQ "All" ( " Thing?
> Can you explain that?
>
> Thank you again for your time guys.
>

The line
For /f "tokens=1" %%a in (C:\mytextfile.txt) do
sets %%a to the first word on each line in c:\mytestfile.txt, one at a time.
Does that file include the word "All"?


Re: ERRORLEVEL
"Al Dunbar" <AlanDrub[ at ]hotmail.com.nospaam> 10/19/2008 6:04:51 PM

"Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
news:DE799BDB-C403-41C1-AF51-C4A6CD728345[ at ]microsoft.com...
[Quoted Text]
> Thank you, I'll give it a try latter, but sounds convincent. What about
> the
> "If /i "%%a" NEQ "All" ( " Thing?
> Can you explain that?

All of the relevent info can be found by typing this command: "if /?"

In brief, what the above does is it conditionally executes the compount
statement between the "(" and the matching ")", but only if the variable
"%%a" contains the word All in any combination of uppercase/lowercase.

/Al

> Thank you again for your time guys.
>
> "Al Dunbar" wrote:
>
>> Sorry, it didn't hit me until I read your last reply, but you the
>> %errorlevel% appears within a compound statement.
>>
>> As is the case with a simple statement, the statement is read in, the
>> environment %variable% references are expanded, and only then the command
>> starts executing. The upshot is that any variable references for all of
>> the
>> statements in a compound statement are expanded before the first
>> statement
>> is executed. And this will be before the execution of any statement that
>> is
>> likely to modify the variables involved. Here is a test script you can
>> run
>> to demonstrate this for yourself:
>>
>> [ at ]echo off
>>
>> setlocal enabledelayedexpansion
>>
>> echo/%date% | find "0"
>> echo/%errorlevel%
>> echo/%date% | find "XX"
>> echo/%errorlevel%
>>
>> for /l %%F in (1,1,1) do (
>> echo/%date% | find "0"
>> echo/%errorlevel%
>> echo/%date% | find "XX"
>> echo/%errorlevel%
>> )
>>
>> for /l %%F in (1,1,1) do (
>> echo/%date% | find "0"
>> echo/!errorlevel!
>> echo/%date% | find "XX"
>> echo/!errorlevel!
>> )
>>
>> pause
>>
>> in each set of commands, the errorlevel value is zero and then some
>> non-zero
>> value. This is accurately displayed in the first set of commands as they
>> are
>> not contained within parentheses. In the second, the values displayed are
>> 1
>> and 1. These are the values the variable had just before the for loop.
>>
>> In the last for loop, the errorlevel values are displayed correctly
>> because
>> the setlocal command enabled delayed expansion, and because "!" was used
>> instead of "%".
>>
>> This is a common issue that catches just about everyone at one time or
>> another because it seems so counter intuitive.
>>
>>
>> /Al
>>
>>
>> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> news:54108A13-F744-4B5F-8709-DC64EA75B507[ at ]microsoft.com...
>> > Hi again and thank you all for you answers. Not sure why but I found
>> > out
>> > that
>> > the problem is that the %errorlevel% doesn't seemed to work (always
>> > returns
>> > the same code error) in the For condition. However if I don't use the
>> > For
>> > condition works pretty well!!! So I'm going to share the answer that I
>> > found.
>> > Basically I create a temporary file and check the results on that file:
>> >
>> > Begin---------------------
>> > cls
>> > net use * /d /y
>> >
>> > Echo. Begin >log.txt
>> > Echo. |date /T >>log.txt
>> > Echo. |time /T >>log.txt
>> > Echo. >>log.txt
>> >
>> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
>> > Echo Username Password ServerIP
>> > Echo %%a %%b %%c
>> >
>> > Net use \\%%c %%b /User:%%a>tmp.txt
>> > Find "The command completed successfully" < tmp.txt > nul
>> > IF NOT ERRORLEVEL 1 (
>> > Echo Connected to %%c >>log.txt
>> > Echo Connected to %%c
>> > ) Else (
>> > Echo Connection Failed for to %%c >>Log.txt
>> > Echo Connection Failed for to %%c
>> > )
>> > del tmp.txt
>> > )
>> > End Batch ---------------------
>> >
>> > For now is working :)
>> >
>> > Another question... I started this batch file from another one that I
>> > found
>> > in the net. The sample was something like this
>> >
>> > For /f "tokens=1" %%a in (C:\mytextfile.txt) do (
>> > If /i "%%a" NEQ "All" (
>> > etc... etc...
>> >
>> > this batch sample was reading servernames from mytextfile.txt and
>> > transfer
>> > files to those servers.
>> >
>> > What I don't full understand is the line "If /i "%%a" NEQ "All" ( "
>> > okay:
>> > "If" is the condition
>> > "/i" - Not sure what it means in this context
>> > "%%a" is variable that represents the "tokens=1"
>> > "NEQ" Not equal
>> > "All" - What is this? Is it trying to get something different from
>> > All???!!
>> >
>> >
>> > Thank you all.
>> >
>> >
>> >
>> >
>> > "Al Dunbar" wrote:
>> >
>> >>
>> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> >> news:5AF5BF0A-2C87-4A6A-8D60-7A62B0EB346B[ at ]microsoft.com...
>> >> > Hi Pegasus and thank you for your time
>> >> > Using the commands on one batch works fine, but when I add them to
>> >> > the
>> >> > batch
>> >> > its stops working??
>> >>
>> >> Note that commands may not always return what you might expect as the
>> >> errorlevel. You sometimes have to find other means to verify the
>> >> success
>> >> or
>> >> failure of the command being tested. For example, if the operation is
>> >> to
>> >> delete a file, then you could test afterwards for its existence.
>> >>
>> >> > Perhaps you can help me if I put the entire script.
>> >> > This is working for successful connections, but when the connection
>> >> > fails
>> >> > or
>> >> > bad username the log is recorded as success "Connected to..."??!!
>> >> >
>> >> > Begin---------------------
>> >> > cls
>> >> > net use * /d /y
>> >> >
>> >> > Echo. Begin >log.txt
>> >> > Echo. |date /T >>log.txt
>> >> > Echo. |time /T >>log.txt
>> >> > Echo. >>log.txt
>> >>
>> >> As an aside, I'd suggest doing this a bit differently:
>> >>
>> >> (
>> >> Echo/ Begin
>> >> Echo/ %date%
>> >> Echo/ %time%
>> >> Echo/
>> >> ) >log.txt
>> >>
>> >> Using the DATE and TIME variables instead of the commands will allow
>> >> them
>> >> to
>> >> appear on the same line:
>> >>
>> >> (
>> >> Echo/ Begin at %time% on %date%
>> >> Echo/
>> >> ) >log.txt
>> >>
>> >> Also, "echo/" is marginally better than "echo.", however I can't quite
>> >> remember why...
>> >>
>> >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
>> >> > Echo Username Password ServerIP
>> >> > Echo %%a %%b %%c
>> >> >
>> >> > Net use \\%%c %%b /User:%%a
>> >> >
>> >> > if %ErrorLevel% EQU 0 (
>> >> > Echo Connected to %%c >>log.txt
>> >> > Echo Connected to %%c
>> >> > ) Else (
>> >> > Echo Connection Failed for to %%c >>log.txt
>> >> > Echo Connection Failed for to %%c
>> >> > )
>> >> > )
>> >> > End Batch ---------------------
>> >> >
>> >> > Thank you
>> >> >
>> >> > "Pegasus (MVP)" wrote:
>> >> >
>> >> >>
>> >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> >> >> news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
>> >> >> > Hi everyone
>> >> >> >
>> >> >> > I'm trying to do errorlevel handling but not with expected
>> >> >> > results:
>> >> >> > Code:
>> >> >> >
>> >> >> > Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
>> >> >> > IF NOT ERRORLEVEL 0 (
>> >> >> > Echo. Connection Failed for to %%a
>> >> >> > Echo. Connection Failed for to %%a >>Log.txt
>> >> >> > ) Else (
>> >> >> > Echo. Connected to %%a
>> >> >> > Echo. Connected to %%a >>Log.txt
>> >> >> > )
>> >> >> >
>> >> >> >
>> >> >> > The problem is that always "Echo. Connected to %%a" not matter if
>> >> >> > it
>> >> >> > fails
>> >> >> > or not, the result is always the saame. Can anyone help me?
>> >> >>
>> >> >> I hate double inverted logic. It goes against human thinking. Why
>> >> >> not
>> >> >> keep
>> >> >> things simple and use direct logic, e.g. like so:
>> >> >> Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
>> >> >> if %ErrorLevel% EQU 0 (
>> >> >> Echo Connected to %%a
>> >> >> Echo Connected to %%a >>Log.txt
>> >> >> ) Else (
>> >> >> Echo Connection Failed for to %%a
>> >> >> Echo Connection Failed for to %%a >>Log.txt
>> >> >> )
>> >> >>
>> >> >> Note the changed syntax: In the above code "ErrorLevel" is an
>> >> >> environmental
>> >> >> variable and "EQU" must be in caps.
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>


Re: ERRORLEVEL
Jmnts 10/19/2008 7:33:00 PM
Hum... That's why is so confusing... The text file doesn't contain anything
with the word "All". That statment is part of a loop to transfer files to a
server. Basically does a dir>>textfile.txt to the file then using the
textfile.txt, transfers all existing files to another server using the move.

By my understanding, basically means that If there's a file named "All" that
file shouldn't be moved?? Am I wrong?




"Al Dunbar" wrote:

[Quoted Text]
>
> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> news:DE799BDB-C403-41C1-AF51-C4A6CD728345[ at ]microsoft.com...
> > Thank you, I'll give it a try latter, but sounds convincent. What about
> > the
> > "If /i "%%a" NEQ "All" ( " Thing?
> > Can you explain that?
>
> All of the relevent info can be found by typing this command: "if /?"
>
> In brief, what the above does is it conditionally executes the compount
> statement between the "(" and the matching ")", but only if the variable
> "%%a" contains the word All in any combination of uppercase/lowercase.
>
> /Al
>
> > Thank you again for your time guys.
> >
> > "Al Dunbar" wrote:
> >
> >> Sorry, it didn't hit me until I read your last reply, but you the
> >> %errorlevel% appears within a compound statement.
> >>
> >> As is the case with a simple statement, the statement is read in, the
> >> environment %variable% references are expanded, and only then the command
> >> starts executing. The upshot is that any variable references for all of
> >> the
> >> statements in a compound statement are expanded before the first
> >> statement
> >> is executed. And this will be before the execution of any statement that
> >> is
> >> likely to modify the variables involved. Here is a test script you can
> >> run
> >> to demonstrate this for yourself:
> >>
> >> [ at ]echo off
> >>
> >> setlocal enabledelayedexpansion
> >>
> >> echo/%date% | find "0"
> >> echo/%errorlevel%
> >> echo/%date% | find "XX"
> >> echo/%errorlevel%
> >>
> >> for /l %%F in (1,1,1) do (
> >> echo/%date% | find "0"
> >> echo/%errorlevel%
> >> echo/%date% | find "XX"
> >> echo/%errorlevel%
> >> )
> >>
> >> for /l %%F in (1,1,1) do (
> >> echo/%date% | find "0"
> >> echo/!errorlevel!
> >> echo/%date% | find "XX"
> >> echo/!errorlevel!
> >> )
> >>
> >> pause
> >>
> >> in each set of commands, the errorlevel value is zero and then some
> >> non-zero
> >> value. This is accurately displayed in the first set of commands as they
> >> are
> >> not contained within parentheses. In the second, the values displayed are
> >> 1
> >> and 1. These are the values the variable had just before the for loop.
> >>
> >> In the last for loop, the errorlevel values are displayed correctly
> >> because
> >> the setlocal command enabled delayed expansion, and because "!" was used
> >> instead of "%".
> >>
> >> This is a common issue that catches just about everyone at one time or
> >> another because it seems so counter intuitive.
> >>
> >>
> >> /Al
> >>
> >>
> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> news:54108A13-F744-4B5F-8709-DC64EA75B507[ at ]microsoft.com...
> >> > Hi again and thank you all for you answers. Not sure why but I found
> >> > out
> >> > that
> >> > the problem is that the %errorlevel% doesn't seemed to work (always
> >> > returns
> >> > the same code error) in the For condition. However if I don't use the
> >> > For
> >> > condition works pretty well!!! So I'm going to share the answer that I
> >> > found.
> >> > Basically I create a temporary file and check the results on that file:
> >> >
> >> > Begin---------------------
> >> > cls
> >> > net use * /d /y
> >> >
> >> > Echo. Begin >log.txt
> >> > Echo. |date /T >>log.txt
> >> > Echo. |time /T >>log.txt
> >> > Echo. >>log.txt
> >> >
> >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> >> > Echo Username Password ServerIP
> >> > Echo %%a %%b %%c
> >> >
> >> > Net use \\%%c %%b /User:%%a>tmp.txt
> >> > Find "The command completed successfully" < tmp.txt > nul
> >> > IF NOT ERRORLEVEL 1 (
> >> > Echo Connected to %%c >>log.txt
> >> > Echo Connected to %%c
> >> > ) Else (
> >> > Echo Connection Failed for to %%c >>Log.txt
> >> > Echo Connection Failed for to %%c
> >> > )
> >> > del tmp.txt
> >> > )
> >> > End Batch ---------------------
> >> >
> >> > For now is working :)
> >> >
> >> > Another question... I started this batch file from another one that I
> >> > found
> >> > in the net. The sample was something like this
> >> >
> >> > For /f "tokens=1" %%a in (C:\mytextfile.txt) do (
> >> > If /i "%%a" NEQ "All" (
> >> > etc... etc...
> >> >
> >> > this batch sample was reading servernames from mytextfile.txt and
> >> > transfer
> >> > files to those servers.
> >> >
> >> > What I don't full understand is the line "If /i "%%a" NEQ "All" ( "
> >> > okay:
> >> > "If" is the condition
> >> > "/i" - Not sure what it means in this context
> >> > "%%a" is variable that represents the "tokens=1"
> >> > "NEQ" Not equal
> >> > "All" - What is this? Is it trying to get something different from
> >> > All???!!
> >> >
> >> >
> >> > Thank you all.
> >> >
> >> >
> >> >
> >> >
> >> > "Al Dunbar" wrote:
> >> >
> >> >>
> >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> >> news:5AF5BF0A-2C87-4A6A-8D60-7A62B0EB346B[ at ]microsoft.com...
> >> >> > Hi Pegasus and thank you for your time
> >> >> > Using the commands on one batch works fine, but when I add them to
> >> >> > the
> >> >> > batch
> >> >> > its stops working??
> >> >>
> >> >> Note that commands may not always return what you might expect as the
> >> >> errorlevel. You sometimes have to find other means to verify the
> >> >> success
> >> >> or
> >> >> failure of the command being tested. For example, if the operation is
> >> >> to
> >> >> delete a file, then you could test afterwards for its existence.
> >> >>
> >> >> > Perhaps you can help me if I put the entire script.
> >> >> > This is working for successful connections, but when the connection
> >> >> > fails
> >> >> > or
> >> >> > bad username the log is recorded as success "Connected to..."??!!
> >> >> >
> >> >> > Begin---------------------
> >> >> > cls
> >> >> > net use * /d /y
> >> >> >
> >> >> > Echo. Begin >log.txt
> >> >> > Echo. |date /T >>log.txt
> >> >> > Echo. |time /T >>log.txt
> >> >> > Echo. >>log.txt
> >> >>
> >> >> As an aside, I'd suggest doing this a bit differently:
> >> >>
> >> >> (
> >> >> Echo/ Begin
> >> >> Echo/ %date%
> >> >> Echo/ %time%
> >> >> Echo/
> >> >> ) >log.txt
> >> >>
> >> >> Using the DATE and TIME variables instead of the commands will allow
> >> >> them
> >> >> to
> >> >> appear on the same line:
> >> >>
> >> >> (
> >> >> Echo/ Begin at %time% on %date%
> >> >> Echo/
> >> >> ) >log.txt
> >> >>
> >> >> Also, "echo/" is marginally better than "echo.", however I can't quite
> >> >> remember why...
> >> >>
> >> >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> >> >> > Echo Username Password ServerIP
> >> >> > Echo %%a %%b %%c
> >> >> >
> >> >> > Net use \\%%c %%b /User:%%a
> >> >> >
> >> >> > if %ErrorLevel% EQU 0 (
> >> >> > Echo Connected to %%c >>log.txt
> >> >> > Echo Connected to %%c
> >> >> > ) Else (
> >> >> > Echo Connection Failed for to %%c >>log.txt
> >> >> > Echo Connection Failed for to %%c
> >> >> > )
> >> >> > )
> >> >> > End Batch ---------------------
> >> >> >
> >> >> > Thank you
> >> >> >
> >> >> > "Pegasus (MVP)" wrote:
> >> >> >
> >> >> >>
> >> >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> >> >> news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
> >> >> >> > Hi everyone
> >> >> >> >
> >> >> >> > I'm trying to do errorlevel handling but not with expected
> >> >> >> > results:
> >> >> >> > Code:
> >> >> >> >
> >> >> >> > Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> >> >> >> > IF NOT ERRORLEVEL 0 (
> >> >> >> > Echo. Connection Failed for to %%a
> >> >> >> > Echo. Connection Failed for to %%a >>Log.txt
> >> >> >> > ) Else (
> >> >> >> > Echo. Connected to %%a
> >> >> >> > Echo. Connected to %%a >>Log.txt
> >> >> >> > )
> >> >> >> >
> >> >> >> >
> >> >> >> > The problem is that always "Echo. Connected to %%a" not matter if
> >> >> >> > it
> >> >> >> > fails
> >> >> >> > or not, the result is always the saame. Can anyone help me?
> >> >> >>
> >> >> >> I hate double inverted logic. It goes against human thinking. Why
> >> >> >> not
> >> >> >> keep
> >> >> >> things simple and use direct logic, e.g. like so:
> >> >> >> Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> >> >> >> if %ErrorLevel% EQU 0 (
> >> >> >> Echo Connected to %%a
> >> >> >> Echo Connected to %%a >>Log.txt
> >> >> >> ) Else (
> >> >> >> Echo Connection Failed for to %%a
> >> >> >> Echo Connection Failed for to %%a >>Log.txt
> >> >> >> )
> >> >> >>
> >> >> >> Note the changed syntax: In the above code "ErrorLevel" is an
> >> >> >> environmental
> >> >> >> variable and "EQU" must be in caps.
> >> >> >>
> >> >> >>
> >> >> >>
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
Re: ERRORLEVEL
Jmnts 10/19/2008 7:38:04 PM
Not sure about the "/i" either... According with IF /?

"The /I switch, if specified, says to do case insensitive string compares.
The /I switch can also be used on the string1==string2 form of IF. These
comparisons are generic, in that if both string1 and string2 are both
comprised of all numeric digits, then the strings are converted to numbers
and a numeric comparison is performed."

According with the sample only one file at the time is loaded to the
textfile.txt, there's no comparison to make? Perhaps the sample not well
written.


"Al Dunbar" wrote:

[Quoted Text]
>
> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> news:DE799BDB-C403-41C1-AF51-C4A6CD728345[ at ]microsoft.com...
> > Thank you, I'll give it a try latter, but sounds convincent. What about
> > the
> > "If /i "%%a" NEQ "All" ( " Thing?
> > Can you explain that?
>
> All of the relevent info can be found by typing this command: "if /?"
>
> In brief, what the above does is it conditionally executes the compount
> statement between the "(" and the matching ")", but only if the variable
> "%%a" contains the word All in any combination of uppercase/lowercase.
>
> /Al
>
> > Thank you again for your time guys.
> >
> > "Al Dunbar" wrote:
> >
> >> Sorry, it didn't hit me until I read your last reply, but you the
> >> %errorlevel% appears within a compound statement.
> >>
> >> As is the case with a simple statement, the statement is read in, the
> >> environment %variable% references are expanded, and only then the command
> >> starts executing. The upshot is that any variable references for all of
> >> the
> >> statements in a compound statement are expanded before the first
> >> statement
> >> is executed. And this will be before the execution of any statement that
> >> is
> >> likely to modify the variables involved. Here is a test script you can
> >> run
> >> to demonstrate this for yourself:
> >>
> >> [ at ]echo off
> >>
> >> setlocal enabledelayedexpansion
> >>
> >> echo/%date% | find "0"
> >> echo/%errorlevel%
> >> echo/%date% | find "XX"
> >> echo/%errorlevel%
> >>
> >> for /l %%F in (1,1,1) do (
> >> echo/%date% | find "0"
> >> echo/%errorlevel%
> >> echo/%date% | find "XX"
> >> echo/%errorlevel%
> >> )
> >>
> >> for /l %%F in (1,1,1) do (
> >> echo/%date% | find "0"
> >> echo/!errorlevel!
> >> echo/%date% | find "XX"
> >> echo/!errorlevel!
> >> )
> >>
> >> pause
> >>
> >> in each set of commands, the errorlevel value is zero and then some
> >> non-zero
> >> value. This is accurately displayed in the first set of commands as they
> >> are
> >> not contained within parentheses. In the second, the values displayed are
> >> 1
> >> and 1. These are the values the variable had just before the for loop.
> >>
> >> In the last for loop, the errorlevel values are displayed correctly
> >> because
> >> the setlocal command enabled delayed expansion, and because "!" was used
> >> instead of "%".
> >>
> >> This is a common issue that catches just about everyone at one time or
> >> another because it seems so counter intuitive.
> >>
> >>
> >> /Al
> >>
> >>
> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> news:54108A13-F744-4B5F-8709-DC64EA75B507[ at ]microsoft.com...
> >> > Hi again and thank you all for you answers. Not sure why but I found
> >> > out
> >> > that
> >> > the problem is that the %errorlevel% doesn't seemed to work (always
> >> > returns
> >> > the same code error) in the For condition. However if I don't use the
> >> > For
> >> > condition works pretty well!!! So I'm going to share the answer that I
> >> > found.
> >> > Basically I create a temporary file and check the results on that file:
> >> >
> >> > Begin---------------------
> >> > cls
> >> > net use * /d /y
> >> >
> >> > Echo. Begin >log.txt
> >> > Echo. |date /T >>log.txt
> >> > Echo. |time /T >>log.txt
> >> > Echo. >>log.txt
> >> >
> >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> >> > Echo Username Password ServerIP
> >> > Echo %%a %%b %%c
> >> >
> >> > Net use \\%%c %%b /User:%%a>tmp.txt
> >> > Find "The command completed successfully" < tmp.txt > nul
> >> > IF NOT ERRORLEVEL 1 (
> >> > Echo Connected to %%c >>log.txt
> >> > Echo Connected to %%c
> >> > ) Else (
> >> > Echo Connection Failed for to %%c >>Log.txt
> >> > Echo Connection Failed for to %%c
> >> > )
> >> > del tmp.txt
> >> > )
> >> > End Batch ---------------------
> >> >
> >> > For now is working :)
> >> >
> >> > Another question... I started this batch file from another one that I
> >> > found
> >> > in the net. The sample was something like this
> >> >
> >> > For /f "tokens=1" %%a in (C:\mytextfile.txt) do (
> >> > If /i "%%a" NEQ "All" (
> >> > etc... etc...
> >> >
> >> > this batch sample was reading servernames from mytextfile.txt and
> >> > transfer
> >> > files to those servers.
> >> >
> >> > What I don't full understand is the line "If /i "%%a" NEQ "All" ( "
> >> > okay:
> >> > "If" is the condition
> >> > "/i" - Not sure what it means in this context
> >> > "%%a" is variable that represents the "tokens=1"
> >> > "NEQ" Not equal
> >> > "All" - What is this? Is it trying to get something different from
> >> > All???!!
> >> >
> >> >
> >> > Thank you all.
> >> >
> >> >
> >> >
> >> >
> >> > "Al Dunbar" wrote:
> >> >
> >> >>
> >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> >> news:5AF5BF0A-2C87-4A6A-8D60-7A62B0EB346B[ at ]microsoft.com...
> >> >> > Hi Pegasus and thank you for your time
> >> >> > Using the commands on one batch works fine, but when I add them to
> >> >> > the
> >> >> > batch
> >> >> > its stops working??
> >> >>
> >> >> Note that commands may not always return what you might expect as the
> >> >> errorlevel. You sometimes have to find other means to verify the
> >> >> success
> >> >> or
> >> >> failure of the command being tested. For example, if the operation is
> >> >> to
> >> >> delete a file, then you could test afterwards for its existence.
> >> >>
> >> >> > Perhaps you can help me if I put the entire script.
> >> >> > This is working for successful connections, but when the connection
> >> >> > fails
> >> >> > or
> >> >> > bad username the log is recorded as success "Connected to..."??!!
> >> >> >
> >> >> > Begin---------------------
> >> >> > cls
> >> >> > net use * /d /y
> >> >> >
> >> >> > Echo. Begin >log.txt
> >> >> > Echo. |date /T >>log.txt
> >> >> > Echo. |time /T >>log.txt
> >> >> > Echo. >>log.txt
> >> >>
> >> >> As an aside, I'd suggest doing this a bit differently:
> >> >>
> >> >> (
> >> >> Echo/ Begin
> >> >> Echo/ %date%
> >> >> Echo/ %time%
> >> >> Echo/
> >> >> ) >log.txt
> >> >>
> >> >> Using the DATE and TIME variables instead of the commands will allow
> >> >> them
> >> >> to
> >> >> appear on the same line:
> >> >>
> >> >> (
> >> >> Echo/ Begin at %time% on %date%
> >> >> Echo/
> >> >> ) >log.txt
> >> >>
> >> >> Also, "echo/" is marginally better than "echo.", however I can't quite
> >> >> remember why...
> >> >>
> >> >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> >> >> > Echo Username Password ServerIP
> >> >> > Echo %%a %%b %%c
> >> >> >
> >> >> > Net use \\%%c %%b /User:%%a
> >> >> >
> >> >> > if %ErrorLevel% EQU 0 (
> >> >> > Echo Connected to %%c >>log.txt
> >> >> > Echo Connected to %%c
> >> >> > ) Else (
> >> >> > Echo Connection Failed for to %%c >>log.txt
> >> >> > Echo Connection Failed for to %%c
> >> >> > )
> >> >> > )
> >> >> > End Batch ---------------------
> >> >> >
> >> >> > Thank you
> >> >> >
> >> >> > "Pegasus (MVP)" wrote:
> >> >> >
> >> >> >>
> >> >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> >> >> news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
> >> >> >> > Hi everyone
> >> >> >> >
> >> >> >> > I'm trying to do errorlevel handling but not with expected
> >> >> >> > results:
> >> >> >> > Code:
> >> >> >> >
> >> >> >> > Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> >> >> >> > IF NOT ERRORLEVEL 0 (
> >> >> >> > Echo. Connection Failed for to %%a
> >> >> >> > Echo. Connection Failed for to %%a >>Log.txt
> >> >> >> > ) Else (
> >> >> >> > Echo. Connected to %%a
> >> >> >> > Echo. Connected to %%a >>Log.txt
> >> >> >> > )
> >> >> >> >
> >> >> >> >
> >> >> >> > The problem is that always "Echo. Connected to %%a" not matter if
> >> >> >> > it
> >> >> >> > fails
> >> >> >> > or not, the result is always the saame. Can anyone help me?
> >> >> >>
> >> >> >> I hate double inverted logic. It goes against human thinking. Why
> >> >> >> not
> >> >> >> keep
> >> >> >> things simple and use direct logic, e.g. like so:
> >> >> >> Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> >> >> >> if %ErrorLevel% EQU 0 (
> >> >> >> Echo Connected to %%a
> >> >> >> Echo Connected to %%a >>Log.txt
> >> >> >> ) Else (
> >> >> >> Echo Connection Failed for to %%a
> >> >> >> Echo Connection Failed for to %%a >>Log.txt
> >> >> >> )
> >> >> >>
> >> >> >> Note the changed syntax: In the above code "ErrorLevel" is an
> >> >> >> environmental
> >> >> >> variable and "EQU" must be in caps.
> >> >> >>
> >> >> >>
> >> >> >>
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
Re: ERRORLEVEL
Jmnts 10/19/2008 7:43:00 PM
Okay... After I write I saw that the /I is to compare the %%a to the "All"...
LOL
Not sure why the "All" but...

"Jmnts" wrote:

[Quoted Text]
> Not sure about the "/i" either... According with IF /?
>
> "The /I switch, if specified, says to do case insensitive string compares.
> The /I switch can also be used on the string1==string2 form of IF. These
> comparisons are generic, in that if both string1 and string2 are both
> comprised of all numeric digits, then the strings are converted to numbers
> and a numeric comparison is performed."
>
> According with the sample only one file at the time is loaded to the
> textfile.txt, there's no comparison to make? Perhaps the sample not well
> written.
>
>
> "Al Dunbar" wrote:
>
> >
> > "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> > news:DE799BDB-C403-41C1-AF51-C4A6CD728345[ at ]microsoft.com...
> > > Thank you, I'll give it a try latter, but sounds convincent. What about
> > > the
> > > "If /i "%%a" NEQ "All" ( " Thing?
> > > Can you explain that?
> >
> > All of the relevent info can be found by typing this command: "if /?"
> >
> > In brief, what the above does is it conditionally executes the compount
> > statement between the "(" and the matching ")", but only if the variable
> > "%%a" contains the word All in any combination of uppercase/lowercase.
> >
> > /Al
> >
> > > Thank you again for your time guys.
> > >
> > > "Al Dunbar" wrote:
> > >
> > >> Sorry, it didn't hit me until I read your last reply, but you the
> > >> %errorlevel% appears within a compound statement.
> > >>
> > >> As is the case with a simple statement, the statement is read in, the
> > >> environment %variable% references are expanded, and only then the command
> > >> starts executing. The upshot is that any variable references for all of
> > >> the
> > >> statements in a compound statement are expanded before the first
> > >> statement
> > >> is executed. And this will be before the execution of any statement that
> > >> is
> > >> likely to modify the variables involved. Here is a test script you can
> > >> run
> > >> to demonstrate this for yourself:
> > >>
> > >> [ at ]echo off
> > >>
> > >> setlocal enabledelayedexpansion
> > >>
> > >> echo/%date% | find "0"
> > >> echo/%errorlevel%
> > >> echo/%date% | find "XX"
> > >> echo/%errorlevel%
> > >>
> > >> for /l %%F in (1,1,1) do (
> > >> echo/%date% | find "0"
> > >> echo/%errorlevel%
> > >> echo/%date% | find "XX"
> > >> echo/%errorlevel%
> > >> )
> > >>
> > >> for /l %%F in (1,1,1) do (
> > >> echo/%date% | find "0"
> > >> echo/!errorlevel!
> > >> echo/%date% | find "XX"
> > >> echo/!errorlevel!
> > >> )
> > >>
> > >> pause
> > >>
> > >> in each set of commands, the errorlevel value is zero and then some
> > >> non-zero
> > >> value. This is accurately displayed in the first set of commands as they
> > >> are
> > >> not contained within parentheses. In the second, the values displayed are
> > >> 1
> > >> and 1. These are the values the variable had just before the for loop.
> > >>
> > >> In the last for loop, the errorlevel values are displayed correctly
> > >> because
> > >> the setlocal command enabled delayed expansion, and because "!" was used
> > >> instead of "%".
> > >>
> > >> This is a common issue that catches just about everyone at one time or
> > >> another because it seems so counter intuitive.
> > >>
> > >>
> > >> /Al
> > >>
> > >>
> > >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> > >> news:54108A13-F744-4B5F-8709-DC64EA75B507[ at ]microsoft.com...
> > >> > Hi again and thank you all for you answers. Not sure why but I found
> > >> > out
> > >> > that
> > >> > the problem is that the %errorlevel% doesn't seemed to work (always
> > >> > returns
> > >> > the same code error) in the For condition. However if I don't use the
> > >> > For
> > >> > condition works pretty well!!! So I'm going to share the answer that I
> > >> > found.
> > >> > Basically I create a temporary file and check the results on that file:
> > >> >
> > >> > Begin---------------------
> > >> > cls
> > >> > net use * /d /y
> > >> >
> > >> > Echo. Begin >log.txt
> > >> > Echo. |date /T >>log.txt
> > >> > Echo. |time /T >>log.txt
> > >> > Echo. >>log.txt
> > >> >
> > >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> > >> > Echo Username Password ServerIP
> > >> > Echo %%a %%b %%c
> > >> >
> > >> > Net use \\%%c %%b /User:%%a>tmp.txt
> > >> > Find "The command completed successfully" < tmp.txt > nul
> > >> > IF NOT ERRORLEVEL 1 (
> > >> > Echo Connected to %%c >>log.txt
> > >> > Echo Connected to %%c
> > >> > ) Else (
> > >> > Echo Connection Failed for to %%c >>Log.txt
> > >> > Echo Connection Failed for to %%c
> > >> > )
> > >> > del tmp.txt
> > >> > )
> > >> > End Batch ---------------------
> > >> >
> > >> > For now is working :)
> > >> >
> > >> > Another question... I started this batch file from another one that I
> > >> > found
> > >> > in the net. The sample was something like this
> > >> >
> > >> > For /f "tokens=1" %%a in (C:\mytextfile.txt) do (
> > >> > If /i "%%a" NEQ "All" (
> > >> > etc... etc...
> > >> >
> > >> > this batch sample was reading servernames from mytextfile.txt and
> > >> > transfer
> > >> > files to those servers.
> > >> >
> > >> > What I don't full understand is the line "If /i "%%a" NEQ "All" ( "
> > >> > okay:
> > >> > "If" is the condition
> > >> > "/i" - Not sure what it means in this context
> > >> > "%%a" is variable that represents the "tokens=1"
> > >> > "NEQ" Not equal
> > >> > "All" - What is this? Is it trying to get something different from
> > >> > All???!!
> > >> >
> > >> >
> > >> > Thank you all.
> > >> >
> > >> >
> > >> >
> > >> >
> > >> > "Al Dunbar" wrote:
> > >> >
> > >> >>
> > >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> > >> >> news:5AF5BF0A-2C87-4A6A-8D60-7A62B0EB346B[ at ]microsoft.com...
> > >> >> > Hi Pegasus and thank you for your time
> > >> >> > Using the commands on one batch works fine, but when I add them to
> > >> >> > the
> > >> >> > batch
> > >> >> > its stops working??
> > >> >>
> > >> >> Note that commands may not always return what you might expect as the
> > >> >> errorlevel. You sometimes have to find other means to verify the
> > >> >> success
> > >> >> or
> > >> >> failure of the command being tested. For example, if the operation is
> > >> >> to
> > >> >> delete a file, then you could test afterwards for its existence.
> > >> >>
> > >> >> > Perhaps you can help me if I put the entire script.
> > >> >> > This is working for successful connections, but when the connection
> > >> >> > fails
> > >> >> > or
> > >> >> > bad username the log is recorded as success "Connected to..."??!!
> > >> >> >
> > >> >> > Begin---------------------
> > >> >> > cls
> > >> >> > net use * /d /y
> > >> >> >
> > >> >> > Echo. Begin >log.txt
> > >> >> > Echo. |date /T >>log.txt
> > >> >> > Echo. |time /T >>log.txt
> > >> >> > Echo. >>log.txt
> > >> >>
> > >> >> As an aside, I'd suggest doing this a bit differently:
> > >> >>
> > >> >> (
> > >> >> Echo/ Begin
> > >> >> Echo/ %date%
> > >> >> Echo/ %time%
> > >> >> Echo/
> > >> >> ) >log.txt
> > >> >>
> > >> >> Using the DATE and TIME variables instead of the commands will allow
> > >> >> them
> > >> >> to
> > >> >> appear on the same line:
> > >> >>
> > >> >> (
> > >> >> Echo/ Begin at %time% on %date%
> > >> >> Echo/
> > >> >> ) >log.txt
> > >> >>
> > >> >> Also, "echo/" is marginally better than "echo.", however I can't quite
> > >> >> remember why...
> > >> >>
> > >> >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> > >> >> > Echo Username Password ServerIP
> > >> >> > Echo %%a %%b %%c
> > >> >> >
> > >> >> > Net use \\%%c %%b /User:%%a
> > >> >> >
> > >> >> > if %ErrorLevel% EQU 0 (
> > >> >> > Echo Connected to %%c >>log.txt
> > >> >> > Echo Connected to %%c
> > >> >> > ) Else (
> > >> >> > Echo Connection Failed for to %%c >>log.txt
> > >> >> > Echo Connection Failed for to %%c
> > >> >> > )
> > >> >> > )
> > >> >> > End Batch ---------------------
> > >> >> >
> > >> >> > Thank you
> > >> >> >
> > >> >> > "Pegasus (MVP)" wrote:
> > >> >> >
> > >> >> >>
> > >> >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> > >> >> >> news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
> > >> >> >> > Hi everyone
> > >> >> >> >
> > >> >> >> > I'm trying to do errorlevel handling but not with expected
> > >> >> >> > results:
> > >> >> >> > Code:
> > >> >> >> >
> > >> >> >> > Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> > >> >> >> > IF NOT ERRORLEVEL 0 (
> > >> >> >> > Echo. Connection Failed for to %%a
> > >> >> >> > Echo. Connection Failed for to %%a >>Log.txt
> > >> >> >> > ) Else (
> > >> >> >> > Echo. Connected to %%a
> > >> >> >> > Echo. Connected to %%a >>Log.txt
> > >> >> >> > )
> > >> >> >> >
> > >> >> >> >
> > >> >> >> > The problem is that always "Echo. Connected to %%a" not matter if
> > >> >> >> > it
> > >> >> >> > fails
> > >> >> >> > or not, the result is always the saame. Can anyone help me?
> > >> >> >>
> > >> >> >> I hate double inverted logic. It goes against human thinking. Why
> > >> >> >> not
> > >> >> >> keep
> > >> >> >> things simple and use direct logic, e.g. like so:
> > >> >> >> Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> > >> >> >> if %ErrorLevel% EQU 0 (
> > >> >> >> Echo Connected to %%a
> > >> >> >> Echo Connected to %%a >>Log.txt
> > >> >> >> ) Else (
> > >> >> >> Echo Connection Failed for to %%a
> > >> >> >> Echo Connection Failed for to %%a >>Log.txt
> > >> >> >> )
> > >> >> >>
> > >> >> >> Note the changed syntax: In the above code "ErrorLevel" is an
> > >> >> >> environmental
> > >> >> >> variable and "EQU" must be in caps.
> > >> >> >>
> > >> >> >>
> > >> >> >>
> > >> >>
> > >> >>
> > >> >>
> > >>
> > >>
> > >>
> >
> >
> >
Re: ERRORLEVEL
"Al Dunbar" <AlanDrub[ at ]hotmail.com.nospaam> 10/20/2008 12:14:12 AM

"Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
news:B98A877F-AD07-4472-AF5E-CFE4045CE2BF[ at ]microsoft.com...
[Quoted Text]
> Okay... After I write I saw that the /I is to compare the %%a to the
> "All"...
> LOL
> Not sure why the "All" but...

To know why the writer of that script included that you would likely need to
ask that person. Given that the text file contains a list of fully qualified
path names, it seems unlikely that any of them would ever be equal to "All".
Perhaps he did this because he wanted to use a compound statement, and did
not realize you only need the parentheses. Alternately, it could be that the
script is not perfect.

Where did this script come from, by the way?

/Al

> "Jmnts" wrote:
>
>> Not sure about the "/i" either... According with IF /?
>>
>> "The /I switch, if specified, says to do case insensitive string
>> compares.
>> The /I switch can also be used on the string1==string2 form of IF. These
>> comparisons are generic, in that if both string1 and string2 are both
>> comprised of all numeric digits, then the strings are converted to
>> numbers
>> and a numeric comparison is performed."
>>
>> According with the sample only one file at the time is loaded to the
>> textfile.txt, there's no comparison to make? Perhaps the sample not well
>> written.
>>
>>
>> "Al Dunbar" wrote:
>>
>> >
>> > "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> > news:DE799BDB-C403-41C1-AF51-C4A6CD728345[ at ]microsoft.com...
>> > > Thank you, I'll give it a try latter, but sounds convincent. What
>> > > about
>> > > the
>> > > "If /i "%%a" NEQ "All" ( " Thing?
>> > > Can you explain that?
>> >
>> > All of the relevent info can be found by typing this command: "if /?"
>> >
>> > In brief, what the above does is it conditionally executes the compount
>> > statement between the "(" and the matching ")", but only if the
>> > variable
>> > "%%a" contains the word All in any combination of uppercase/lowercase.
>> >
>> > /Al
>> >
>> > > Thank you again for your time guys.
>> > >
>> > > "Al Dunbar" wrote:
>> > >
>> > >> Sorry, it didn't hit me until I read your last reply, but you the
>> > >> %errorlevel% appears within a compound statement.
>> > >>
>> > >> As is the case with a simple statement, the statement is read in,
>> > >> the
>> > >> environment %variable% references are expanded, and only then the
>> > >> command
>> > >> starts executing. The upshot is that any variable references for all
>> > >> of
>> > >> the
>> > >> statements in a compound statement are expanded before the first
>> > >> statement
>> > >> is executed. And this will be before the execution of any statement
>> > >> that
>> > >> is
>> > >> likely to modify the variables involved. Here is a test script you
>> > >> can
>> > >> run
>> > >> to demonstrate this for yourself:
>> > >>
>> > >> [ at ]echo off
>> > >>
>> > >> setlocal enabledelayedexpansion
>> > >>
>> > >> echo/%date% | find "0"
>> > >> echo/%errorlevel%
>> > >> echo/%date% | find "XX"
>> > >> echo/%errorlevel%
>> > >>
>> > >> for /l %%F in (1,1,1) do (
>> > >> echo/%date% | find "0"
>> > >> echo/%errorlevel%
>> > >> echo/%date% | find "XX"
>> > >> echo/%errorlevel%
>> > >> )
>> > >>
>> > >> for /l %%F in (1,1,1) do (
>> > >> echo/%date% | find "0"
>> > >> echo/!errorlevel!
>> > >> echo/%date% | find "XX"
>> > >> echo/!errorlevel!
>> > >> )
>> > >>
>> > >> pause
>> > >>
>> > >> in each set of commands, the errorlevel value is zero and then some
>> > >> non-zero
>> > >> value. This is accurately displayed in the first set of commands as
>> > >> they
>> > >> are
>> > >> not contained within parentheses. In the second, the values
>> > >> displayed are
>> > >> 1
>> > >> and 1. These are the values the variable had just before the for
>> > >> loop.
>> > >>
>> > >> In the last for loop, the errorlevel values are displayed correctly
>> > >> because
>> > >> the setlocal command enabled delayed expansion, and because "!" was
>> > >> used
>> > >> instead of "%".
>> > >>
>> > >> This is a common issue that catches just about everyone at one time
>> > >> or
>> > >> another because it seems so counter intuitive.
>> > >>
>> > >>
>> > >> /Al
>> > >>
>> > >>
>> > >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> > >> news:54108A13-F744-4B5F-8709-DC64EA75B507[ at ]microsoft.com...
>> > >> > Hi again and thank you all for you answers. Not sure why but I
>> > >> > found
>> > >> > out
>> > >> > that
>> > >> > the problem is that the %errorlevel% doesn't seemed to work
>> > >> > (always
>> > >> > returns
>> > >> > the same code error) in the For condition. However if I don't use
>> > >> > the
>> > >> > For
>> > >> > condition works pretty well!!! So I'm going to share the answer
>> > >> > that I
>> > >> > found.
>> > >> > Basically I create a temporary file and check the results on that
>> > >> > file:
>> > >> >
>> > >> > Begin---------------------
>> > >> > cls
>> > >> > net use * /d /y
>> > >> >
>> > >> > Echo. Begin >log.txt
>> > >> > Echo. |date /T >>log.txt
>> > >> > Echo. |time /T >>log.txt
>> > >> > Echo. >>log.txt
>> > >> >
>> > >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
>> > >> > Echo Username Password ServerIP
>> > >> > Echo %%a %%b %%c
>> > >> >
>> > >> > Net use \\%%c %%b /User:%%a>tmp.txt
>> > >> > Find "The command completed successfully" < tmp.txt > nul
>> > >> > IF NOT ERRORLEVEL 1 (
>> > >> > Echo Connected to %%c >>log.txt
>> > >> > Echo Connected to %%c
>> > >> > ) Else (
>> > >> > Echo Connection Failed for to %%c >>Log.txt
>> > >> > Echo Connection Failed for to %%c
>> > >> > )
>> > >> > del tmp.txt
>> > >> > )
>> > >> > End Batch ---------------------
>> > >> >
>> > >> > For now is working :)
>> > >> >
>> > >> > Another question... I started this batch file from another one
>> > >> > that I
>> > >> > found
>> > >> > in the net. The sample was something like this
>> > >> >
>> > >> > For /f "tokens=1" %%a in (C:\mytextfile.txt) do (
>> > >> > If /i "%%a" NEQ "All" (
>> > >> > etc... etc...
>> > >> >
>> > >> > this batch sample was reading servernames from mytextfile.txt and
>> > >> > transfer
>> > >> > files to those servers.
>> > >> >
>> > >> > What I don't full understand is the line "If /i "%%a" NEQ "All"
>> > >> > ( "
>> > >> > okay:
>> > >> > "If" is the condition
>> > >> > "/i" - Not sure what it means in this context
>> > >> > "%%a" is variable that represents the "tokens=1"
>> > >> > "NEQ" Not equal
>> > >> > "All" - What is this? Is it trying to get something different from
>> > >> > All???!!
>> > >> >
>> > >> >
>> > >> > Thank you all.
>> > >> >
>> > >> >
>> > >> >
>> > >> >
>> > >> > "Al Dunbar" wrote:
>> > >> >
>> > >> >>
>> > >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> > >> >> news:5AF5BF0A-2C87-4A6A-8D60-7A62B0EB346B[ at ]microsoft.com...
>> > >> >> > Hi Pegasus and thank you for your time
>> > >> >> > Using the commands on one batch works fine, but when I add them
>> > >> >> > to
>> > >> >> > the
>> > >> >> > batch
>> > >> >> > its stops working??
>> > >> >>
>> > >> >> Note that commands may not always return what you might expect as
>> > >> >> the
>> > >> >> errorlevel. You sometimes have to find other means to verify the
>> > >> >> success
>> > >> >> or
>> > >> >> failure of the command being tested. For example, if the
>> > >> >> operation is
>> > >> >> to
>> > >> >> delete a file, then you could test afterwards for its existence.
>> > >> >>
>> > >> >> > Perhaps you can help me if I put the entire script.
>> > >> >> > This is working for successful connections, but when the
>> > >> >> > connection
>> > >> >> > fails
>> > >> >> > or
>> > >> >> > bad username the log is recorded as success "Connected
>> > >> >> > to..."??!!
>> > >> >> >
>> > >> >> > Begin---------------------
>> > >> >> > cls
>> > >> >> > net use * /d /y
>> > >> >> >
>> > >> >> > Echo. Begin >log.txt
>> > >> >> > Echo. |date /T >>log.txt
>> > >> >> > Echo. |time /T >>log.txt
>> > >> >> > Echo. >>log.txt
>> > >> >>
>> > >> >> As an aside, I'd suggest doing this a bit differently:
>> > >> >>
>> > >> >> (
>> > >> >> Echo/ Begin
>> > >> >> Echo/ %date%
>> > >> >> Echo/ %time%
>> > >> >> Echo/
>> > >> >> ) >log.txt
>> > >> >>
>> > >> >> Using the DATE and TIME variables instead of the commands will
>> > >> >> allow
>> > >> >> them
>> > >> >> to
>> > >> >> appear on the same line:
>> > >> >>
>> > >> >> (
>> > >> >> Echo/ Begin at %time% on %date%
>> > >> >> Echo/
>> > >> >> ) >log.txt
>> > >> >>
>> > >> >> Also, "echo/" is marginally better than "echo.", however I can't
>> > >> >> quite
>> > >> >> remember why...
>> > >> >>
>> > >> >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
>> > >> >> > Echo Username Password ServerIP
>> > >> >> > Echo %%a %%b %%c
>> > >> >> >
>> > >> >> > Net use \\%%c %%b /User:%%a
>> > >> >> >
>> > >> >> > if %ErrorLevel% EQU 0 (
>> > >> >> > Echo Connected to %%c >>log.txt
>> > >> >> > Echo Connected to %%c
>> > >> >> > ) Else (
>> > >> >> > Echo Connection Failed for to %%c >>log.txt
>> > >> >> > Echo Connection Failed for to %%c
>> > >> >> > )
>> > >> >> > )
>> > >> >> > End Batch ---------------------
>> > >> >> >
>> > >> >> > Thank you
>> > >> >> >
>> > >> >> > "Pegasus (MVP)" wrote:
>> > >> >> >
>> > >> >> >>
>> > >> >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> > >> >> >> news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
>> > >> >> >> > Hi everyone
>> > >> >> >> >
>> > >> >> >> > I'm trying to do errorlevel handling but not with expected
>> > >> >> >> > results:
>> > >> >> >> > Code:
>> > >> >> >> >
>> > >> >> >> > Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
>> > >> >> >> > IF NOT ERRORLEVEL 0 (
>> > >> >> >> > Echo. Connection Failed for to %%a
>> > >> >> >> > Echo. Connection Failed for to %%a >>Log.txt
>> > >> >> >> > ) Else (
>> > >> >> >> > Echo. Connected to %%a
>> > >> >> >> > Echo. Connected to %%a >>Log.txt
>> > >> >> >> > )
>> > >> >> >> >
>> > >> >> >> >
>> > >> >> >> > The problem is that always "Echo. Connected to %%a" not
>> > >> >> >> > matter if
>> > >> >> >> > it
>> > >> >> >> > fails
>> > >> >> >> > or not, the result is always the saame. Can anyone help me?
>> > >> >> >>
>> > >> >> >> I hate double inverted logic. It goes against human thinking.
>> > >> >> >> Why
>> > >> >> >> not
>> > >> >> >> keep
>> > >> >> >> things simple and use direct logic, e.g. like so:
>> > >> >> >> Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
>> > >> >> >> if %ErrorLevel% EQU 0 (
>> > >> >> >> Echo Connected to %%a
>> > >> >> >> Echo Connected to %%a >>Log.txt
>> > >> >> >> ) Else (
>> > >> >> >> Echo Connection Failed for to %%a
>> > >> >> >> Echo Connection Failed for to %%a >>Log.txt
>> > >> >> >> )
>> > >> >> >>
>> > >> >> >> Note the changed syntax: In the above code "ErrorLevel" is an
>> > >> >> >> environmental
>> > >> >> >> variable and "EQU" must be in caps.
>> > >> >> >>
>> > >> >> >>
>> > >> >> >>
>> > >> >>
>> > >> >>
>> > >> >>
>> > >>
>> > >>
>> > >>
>> >
>> >
>> >


Re: ERRORLEVEL
Jmnts 10/20/2008 12:32:00 AM
The file.txt doesn't contain the fully qualified path names, it only contains
the name of the files to be transfered... That's why it's hard to hunderstand
the "All" unless the variable %%a must not be equal to a file named "All".

Not sure where (I don't remember the URL) but a google search shows
something similar at
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_22779605.html

Again, in this is example everything is clear, except the "All" thing... The
%%a must not be equal to "All", is "All"=Null? or Empty string or a space...


"Al Dunbar" wrote:

[Quoted Text]
>
> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> news:B98A877F-AD07-4472-AF5E-CFE4045CE2BF[ at ]microsoft.com...
> > Okay... After I write I saw that the /I is to compare the %%a to the
> > "All"...
> > LOL
> > Not sure why the "All" but...
>
> To know why the writer of that script included that you would likely need to
> ask that person. Given that the text file contains a list of fully qualified
> path names, it seems unlikely that any of them would ever be equal to "All".
> Perhaps he did this because he wanted to use a compound statement, and did
> not realize you only need the parentheses. Alternately, it could be that the
> script is not perfect.
>
> Where did this script come from, by the way?
>
> /Al
>
> > "Jmnts" wrote:
> >
> >> Not sure about the "/i" either... According with IF /?
> >>
> >> "The /I switch, if specified, says to do case insensitive string
> >> compares.
> >> The /I switch can also be used on the string1==string2 form of IF. These
> >> comparisons are generic, in that if both string1 and string2 are both
> >> comprised of all numeric digits, then the strings are converted to
> >> numbers
> >> and a numeric comparison is performed."
> >>
> >> According with the sample only one file at the time is loaded to the
> >> textfile.txt, there's no comparison to make? Perhaps the sample not well
> >> written.
> >>
> >>
> >> "Al Dunbar" wrote:
> >>
> >> >
> >> > "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> > news:DE799BDB-C403-41C1-AF51-C4A6CD728345[ at ]microsoft.com...
> >> > > Thank you, I'll give it a try latter, but sounds convincent. What
> >> > > about
> >> > > the
> >> > > "If /i "%%a" NEQ "All" ( " Thing?
> >> > > Can you explain that?
> >> >
> >> > All of the relevent info can be found by typing this command: "if /?"
> >> >
> >> > In brief, what the above does is it conditionally executes the compount
> >> > statement between the "(" and the matching ")", but only if the
> >> > variable
> >> > "%%a" contains the word All in any combination of uppercase/lowercase.
> >> >
> >> > /Al
> >> >
> >> > > Thank you again for your time guys.
> >> > >
> >> > > "Al Dunbar" wrote:
> >> > >
> >> > >> Sorry, it didn't hit me until I read your last reply, but you the
> >> > >> %errorlevel% appears within a compound statement.
> >> > >>
> >> > >> As is the case with a simple statement, the statement is read in,
> >> > >> the
> >> > >> environment %variable% references are expanded, and only then the
> >> > >> command
> >> > >> starts executing. The upshot is that any variable references for all
> >> > >> of
> >> > >> the
> >> > >> statements in a compound statement are expanded before the first
> >> > >> statement
> >> > >> is executed. And this will be before the execution of any statement
> >> > >> that
> >> > >> is
> >> > >> likely to modify the variables involved. Here is a test script you
> >> > >> can
> >> > >> run
> >> > >> to demonstrate this for yourself:
> >> > >>
> >> > >> [ at ]echo off
> >> > >>
> >> > >> setlocal enabledelayedexpansion
> >> > >>
> >> > >> echo/%date% | find "0"
> >> > >> echo/%errorlevel%
> >> > >> echo/%date% | find "XX"
> >> > >> echo/%errorlevel%
> >> > >>
> >> > >> for /l %%F in (1,1,1) do (
> >> > >> echo/%date% | find "0"
> >> > >> echo/%errorlevel%
> >> > >> echo/%date% | find "XX"
> >> > >> echo/%errorlevel%
> >> > >> )
> >> > >>
> >> > >> for /l %%F in (1,1,1) do (
> >> > >> echo/%date% | find "0"
> >> > >> echo/!errorlevel!
> >> > >> echo/%date% | find "XX"
> >> > >> echo/!errorlevel!
> >> > >> )
> >> > >>
> >> > >> pause
> >> > >>
> >> > >> in each set of commands, the errorlevel value is zero and then some
> >> > >> non-zero
> >> > >> value. This is accurately displayed in the first set of commands as
> >> > >> they
> >> > >> are
> >> > >> not contained within parentheses. In the second, the values
> >> > >> displayed are
> >> > >> 1
> >> > >> and 1. These are the values the variable had just before the for
> >> > >> loop.
> >> > >>
> >> > >> In the last for loop, the errorlevel values are displayed correctly
> >> > >> because
> >> > >> the setlocal command enabled delayed expansion, and because "!" was
> >> > >> used
> >> > >> instead of "%".
> >> > >>
> >> > >> This is a common issue that catches just about everyone at one time
> >> > >> or
> >> > >> another because it seems so counter intuitive.
> >> > >>
> >> > >>
> >> > >> /Al
> >> > >>
> >> > >>
> >> > >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> > >> news:54108A13-F744-4B5F-8709-DC64EA75B507[ at ]microsoft.com...
> >> > >> > Hi again and thank you all for you answers. Not sure why but I
> >> > >> > found
> >> > >> > out
> >> > >> > that
> >> > >> > the problem is that the %errorlevel% doesn't seemed to work
> >> > >> > (always
> >> > >> > returns
> >> > >> > the same code error) in the For condition. However if I don't use
> >> > >> > the
> >> > >> > For
> >> > >> > condition works pretty well!!! So I'm going to share the answer
> >> > >> > that I
> >> > >> > found.
> >> > >> > Basically I create a temporary file and check the results on that
> >> > >> > file:
> >> > >> >
> >> > >> > Begin---------------------
> >> > >> > cls
> >> > >> > net use * /d /y
> >> > >> >
> >> > >> > Echo. Begin >log.txt
> >> > >> > Echo. |date /T >>log.txt
> >> > >> > Echo. |time /T >>log.txt
> >> > >> > Echo. >>log.txt
> >> > >> >
> >> > >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> >> > >> > Echo Username Password ServerIP
> >> > >> > Echo %%a %%b %%c
> >> > >> >
> >> > >> > Net use \\%%c %%b /User:%%a>tmp.txt
> >> > >> > Find "The command completed successfully" < tmp.txt > nul
> >> > >> > IF NOT ERRORLEVEL 1 (
> >> > >> > Echo Connected to %%c >>log.txt
> >> > >> > Echo Connected to %%c
> >> > >> > ) Else (
> >> > >> > Echo Connection Failed for to %%c >>Log.txt
> >> > >> > Echo Connection Failed for to %%c
> >> > >> > )
> >> > >> > del tmp.txt
> >> > >> > )
> >> > >> > End Batch ---------------------
> >> > >> >
> >> > >> > For now is working :)
> >> > >> >
> >> > >> > Another question... I started this batch file from another one
> >> > >> > that I
> >> > >> > found
> >> > >> > in the net. The sample was something like this
> >> > >> >
> >> > >> > For /f "tokens=1" %%a in (C:\mytextfile.txt) do (
> >> > >> > If /i "%%a" NEQ "All" (
> >> > >> > etc... etc...
> >> > >> >
> >> > >> > this batch sample was reading servernames from mytextfile.txt and
> >> > >> > transfer
> >> > >> > files to those servers.
> >> > >> >
> >> > >> > What I don't full understand is the line "If /i "%%a" NEQ "All"
> >> > >> > ( "
> >> > >> > okay:
> >> > >> > "If" is the condition
> >> > >> > "/i" - Not sure what it means in this context
> >> > >> > "%%a" is variable that represents the "tokens=1"
> >> > >> > "NEQ" Not equal
> >> > >> > "All" - What is this? Is it trying to get something different from
> >> > >> > All???!!
> >> > >> >
> >> > >> >
> >> > >> > Thank you all.
> >> > >> >
> >> > >> >
> >> > >> >
> >> > >> >
> >> > >> > "Al Dunbar" wrote:
> >> > >> >
> >> > >> >>
> >> > >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> > >> >> news:5AF5BF0A-2C87-4A6A-8D60-7A62B0EB346B[ at ]microsoft.com...
> >> > >> >> > Hi Pegasus and thank you for your time
> >> > >> >> > Using the commands on one batch works fine, but when I add them
> >> > >> >> > to
> >> > >> >> > the
> >> > >> >> > batch
> >> > >> >> > its stops working??
> >> > >> >>
> >> > >> >> Note that commands may not always return what you might expect as
> >> > >> >> the
> >> > >> >> errorlevel. You sometimes have to find other means to verify the
> >> > >> >> success
> >> > >> >> or
> >> > >> >> failure of the command being tested. For example, if the
> >> > >> >> operation is
> >> > >> >> to
> >> > >> >> delete a file, then you could test afterwards for its existence.
> >> > >> >>
> >> > >> >> > Perhaps you can help me if I put the entire script.
> >> > >> >> > This is working for successful connections, but when the
> >> > >> >> > connection
> >> > >> >> > fails
> >> > >> >> > or
> >> > >> >> > bad username the log is recorded as success "Connected
> >> > >> >> > to..."??!!
> >> > >> >> >
> >> > >> >> > Begin---------------------
> >> > >> >> > cls
> >> > >> >> > net use * /d /y
> >> > >> >> >
> >> > >> >> > Echo. Begin >log.txt
> >> > >> >> > Echo. |date /T >>log.txt
> >> > >> >> > Echo. |time /T >>log.txt
> >> > >> >> > Echo. >>log.txt
> >> > >> >>
> >> > >> >> As an aside, I'd suggest doing this a bit differently:
> >> > >> >>
> >> > >> >> (
> >> > >> >> Echo/ Begin
> >> > >> >> Echo/ %date%
> >> > >> >> Echo/ %time%
> >> > >> >> Echo/
> >> > >> >> ) >log.txt
> >> > >> >>
> >> > >> >> Using the DATE and TIME variables instead of the commands will
> >> > >> >> allow
> >> > >> >> them
> >> > >> >> to
> >> > >> >> appear on the same line:
> >> > >> >>
> >> > >> >> (
> >> > >> >> Echo/ Begin at %time% on %date%
> >> > >> >> Echo/
> >> > >> >> ) >log.txt
> >> > >> >>
> >> > >> >> Also, "echo/" is marginally better than "echo.", however I can't
> >> > >> >> quite
> >> > >> >> remember why...
> >> > >> >>
> >> > >> >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
> >> > >> >> > Echo Username Password ServerIP
> >> > >> >> > Echo %%a %%b %%c
> >> > >> >> >
> >> > >> >> > Net use \\%%c %%b /User:%%a
> >> > >> >> >
> >> > >> >> > if %ErrorLevel% EQU 0 (
> >> > >> >> > Echo Connected to %%c >>log.txt
> >> > >> >> > Echo Connected to %%c
> >> > >> >> > ) Else (
> >> > >> >> > Echo Connection Failed for to %%c >>log.txt
> >> > >> >> > Echo Connection Failed for to %%c
> >> > >> >> > )
> >> > >> >> > )
> >> > >> >> > End Batch ---------------------
> >> > >> >> >
> >> > >> >> > Thank you
> >> > >> >> >
> >> > >> >> > "Pegasus (MVP)" wrote:
> >> > >> >> >
> >> > >> >> >>
> >> > >> >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
> >> > >> >> >> news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
> >> > >> >> >> > Hi everyone
> >> > >> >> >> >
> >> > >> >> >> > I'm trying to do errorlevel handling but not with expected
> >> > >> >> >> > results:
> >> > >> >> >> > Code:
> >> > >> >> >> >
> >> > >> >> >> > Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
> >> > >> >> >> > IF NOT ERRORLEVEL 0 (
> >> > >> >> >> > Echo. Connection Failed for to %%a
> >> > >> >> >> > Echo. Connection Failed for to %%a >>Log.txt
Re: ERRORLEVEL
"Al Dunbar" <AlanDrub[ at ]hotmail.com.nospaam> 10/20/2008 4:53:55 AM

"Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
news:88787F3B-38F3-4516-9057-AA4504F2F2DC[ at ]microsoft.com...
[Quoted Text]
> The file.txt doesn't contain the fully qualified path names, it only
> contains
> the name of the files to be transfered... That's why it's hard to
> hunderstand
> the "All" unless the variable %%a must not be equal to a file named "All".

Again, if there were a purpose for this, the person most likely aware what
the intent was would be the person who wrote the script.

> Not sure where (I don't remember the URL) but a google search shows
> something similar at

When you say "not sure where", is this your response to my question "Where
did this script come from?". Are you saying that you do not know where the
script came from, but that, at the same time, and while not being sure what
it does or is intended to do, you are running it in your environment? For
some other purpose?

If so, instead of running an unknown script that does not do what you want
and trying to modify it so it does, why don't you decide what it is you want
to do, and write a script to do that?

> http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_22779605.html
>
> Again, in this is example everything is clear, except the "All" thing...

No, that part is perfectly clear. In this case the text file contains a list
of account names, not files. And, like the post says that this filters out
"All" and "Administrator". The problem is that he wants it to filter out any
account whose name starts with "admin"

> The
> %%a must not be equal to "All", is "All"=Null? or Empty string or a
> space...

No, you are reading far too much into this. Sometimes a cigar is just a
cigar, but in scripting "All" is *always* just an "All.

As I hinted above, I am now confused as to your purpose. What is it you want
to do:

a) understand what this script does;
b) understand what it is supposed to do this; or:
c) change it so it does something else?

/Al

>
>
> "Al Dunbar" wrote:
>
>>
>> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> news:B98A877F-AD07-4472-AF5E-CFE4045CE2BF[ at ]microsoft.com...
>> > Okay... After I write I saw that the /I is to compare the %%a to the
>> > "All"...
>> > LOL
>> > Not sure why the "All" but...
>>
>> To know why the writer of that script included that you would likely need
>> to
>> ask that person. Given that the text file contains a list of fully
>> qualified
>> path names, it seems unlikely that any of them would ever be equal to
>> "All".
>> Perhaps he did this because he wanted to use a compound statement, and
>> did
>> not realize you only need the parentheses. Alternately, it could be that
>> the
>> script is not perfect.
>>
>> Where did this script come from, by the way?
>>
>> /Al
>>
>> > "Jmnts" wrote:
>> >
>> >> Not sure about the "/i" either... According with IF /?
>> >>
>> >> "The /I switch, if specified, says to do case insensitive string
>> >> compares.
>> >> The /I switch can also be used on the string1==string2 form of IF.
>> >> These
>> >> comparisons are generic, in that if both string1 and string2 are both
>> >> comprised of all numeric digits, then the strings are converted to
>> >> numbers
>> >> and a numeric comparison is performed."
>> >>
>> >> According with the sample only one file at the time is loaded to the
>> >> textfile.txt, there's no comparison to make? Perhaps the sample not
>> >> well
>> >> written.
>> >>
>> >>
>> >> "Al Dunbar" wrote:
>> >>
>> >> >
>> >> > "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> >> > news:DE799BDB-C403-41C1-AF51-C4A6CD728345[ at ]microsoft.com...
>> >> > > Thank you, I'll give it a try latter, but sounds convincent. What
>> >> > > about
>> >> > > the
>> >> > > "If /i "%%a" NEQ "All" ( " Thing?
>> >> > > Can you explain that?
>> >> >
>> >> > All of the relevent info can be found by typing this command: "if
>> >> > /?"
>> >> >
>> >> > In brief, what the above does is it conditionally executes the
>> >> > compount
>> >> > statement between the "(" and the matching ")", but only if the
>> >> > variable
>> >> > "%%a" contains the word All in any combination of
>> >> > uppercase/lowercase.
>> >> >
>> >> > /Al
>> >> >
>> >> > > Thank you again for your time guys.
>> >> > >
>> >> > > "Al Dunbar" wrote:
>> >> > >
>> >> > >> Sorry, it didn't hit me until I read your last reply, but you the
>> >> > >> %errorlevel% appears within a compound statement.
>> >> > >>
>> >> > >> As is the case with a simple statement, the statement is read in,
>> >> > >> the
>> >> > >> environment %variable% references are expanded, and only then the
>> >> > >> command
>> >> > >> starts executing. The upshot is that any variable references for
>> >> > >> all
>> >> > >> of
>> >> > >> the
>> >> > >> statements in a compound statement are expanded before the first
>> >> > >> statement
>> >> > >> is executed. And this will be before the execution of any
>> >> > >> statement
>> >> > >> that
>> >> > >> is
>> >> > >> likely to modify the variables involved. Here is a test script
>> >> > >> you
>> >> > >> can
>> >> > >> run
>> >> > >> to demonstrate this for yourself:
>> >> > >>
>> >> > >> [ at ]echo off
>> >> > >>
>> >> > >> setlocal enabledelayedexpansion
>> >> > >>
>> >> > >> echo/%date% | find "0"
>> >> > >> echo/%errorlevel%
>> >> > >> echo/%date% | find "XX"
>> >> > >> echo/%errorlevel%
>> >> > >>
>> >> > >> for /l %%F in (1,1,1) do (
>> >> > >> echo/%date% | find "0"
>> >> > >> echo/%errorlevel%
>> >> > >> echo/%date% | find "XX"
>> >> > >> echo/%errorlevel%
>> >> > >> )
>> >> > >>
>> >> > >> for /l %%F in (1,1,1) do (
>> >> > >> echo/%date% | find "0"
>> >> > >> echo/!errorlevel!
>> >> > >> echo/%date% | find "XX"
>> >> > >> echo/!errorlevel!
>> >> > >> )
>> >> > >>
>> >> > >> pause
>> >> > >>
>> >> > >> in each set of commands, the errorlevel value is zero and then
>> >> > >> some
>> >> > >> non-zero
>> >> > >> value. This is accurately displayed in the first set of commands
>> >> > >> as
>> >> > >> they
>> >> > >> are
>> >> > >> not contained within parentheses. In the second, the values
>> >> > >> displayed are
>> >> > >> 1
>> >> > >> and 1. These are the values the variable had just before the for
>> >> > >> loop.
>> >> > >>
>> >> > >> In the last for loop, the errorlevel values are displayed
>> >> > >> correctly
>> >> > >> because
>> >> > >> the setlocal command enabled delayed expansion, and because "!"
>> >> > >> was
>> >> > >> used
>> >> > >> instead of "%".
>> >> > >>
>> >> > >> This is a common issue that catches just about everyone at one
>> >> > >> time
>> >> > >> or
>> >> > >> another because it seems so counter intuitive.
>> >> > >>
>> >> > >>
>> >> > >> /Al
>> >> > >>
>> >> > >>
>> >> > >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> >> > >> news:54108A13-F744-4B5F-8709-DC64EA75B507[ at ]microsoft.com...
>> >> > >> > Hi again and thank you all for you answers. Not sure why but I
>> >> > >> > found
>> >> > >> > out
>> >> > >> > that
>> >> > >> > the problem is that the %errorlevel% doesn't seemed to work
>> >> > >> > (always
>> >> > >> > returns
>> >> > >> > the same code error) in the For condition. However if I don't
>> >> > >> > use
>> >> > >> > the
>> >> > >> > For
>> >> > >> > condition works pretty well!!! So I'm going to share the answer
>> >> > >> > that I
>> >> > >> > found.
>> >> > >> > Basically I create a temporary file and check the results on
>> >> > >> > that
>> >> > >> > file:
>> >> > >> >
>> >> > >> > Begin---------------------
>> >> > >> > cls
>> >> > >> > net use * /d /y
>> >> > >> >
>> >> > >> > Echo. Begin >log.txt
>> >> > >> > Echo. |date /T >>log.txt
>> >> > >> > Echo. |time /T >>log.txt
>> >> > >> > Echo. >>log.txt
>> >> > >> >
>> >> > >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
>> >> > >> > Echo Username Password ServerIP
>> >> > >> > Echo %%a %%b %%c
>> >> > >> >
>> >> > >> > Net use \\%%c %%b /User:%%a>tmp.txt
>> >> > >> > Find "The command completed successfully" < tmp.txt > nul
>> >> > >> > IF NOT ERRORLEVEL 1 (
>> >> > >> > Echo Connected to %%c >>log.txt
>> >> > >> > Echo Connected to %%c
>> >> > >> > ) Else (
>> >> > >> > Echo Connection Failed for to %%c >>Log.txt
>> >> > >> > Echo Connection Failed for to %%c
>> >> > >> > )
>> >> > >> > del tmp.txt
>> >> > >> > )
>> >> > >> > End Batch ---------------------
>> >> > >> >
>> >> > >> > For now is working :)
>> >> > >> >
>> >> > >> > Another question... I started this batch file from another one
>> >> > >> > that I
>> >> > >> > found
>> >> > >> > in the net. The sample was something like this
>> >> > >> >
>> >> > >> > For /f "tokens=1" %%a in (C:\mytextfile.txt) do (
>> >> > >> > If /i "%%a" NEQ "All" (
>> >> > >> > etc... etc...
>> >> > >> >
>> >> > >> > this batch sample was reading servernames from mytextfile.txt
>> >> > >> > and
>> >> > >> > transfer
>> >> > >> > files to those servers.
>> >> > >> >
>> >> > >> > What I don't full understand is the line "If /i "%%a" NEQ
>> >> > >> > "All"
>> >> > >> > ( "
>> >> > >> > okay:
>> >> > >> > "If" is the condition
>> >> > >> > "/i" - Not sure what it means in this context
>> >> > >> > "%%a" is variable that represents the "tokens=1"
>> >> > >> > "NEQ" Not equal
>> >> > >> > "All" - What is this? Is it trying to get something different
>> >> > >> > from
>> >> > >> > All???!!
>> >> > >> >
>> >> > >> >
>> >> > >> > Thank you all.
>> >> > >> >
>> >> > >> >
>> >> > >> >
>> >> > >> >
>> >> > >> > "Al Dunbar" wrote:
>> >> > >> >
>> >> > >> >>
>> >> > >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> >> > >> >> news:5AF5BF0A-2C87-4A6A-8D60-7A62B0EB346B[ at ]microsoft.com...
>> >> > >> >> > Hi Pegasus and thank you for your time
>> >> > >> >> > Using the commands on one batch works fine, but when I add
>> >> > >> >> > them
>> >> > >> >> > to
>> >> > >> >> > the
>> >> > >> >> > batch
>> >> > >> >> > its stops working??
>> >> > >> >>
>> >> > >> >> Note that commands may not always return what you might expect
>> >> > >> >> as
>> >> > >> >> the
>> >> > >> >> errorlevel. You sometimes have to find other means to verify
>> >> > >> >> the
>> >> > >> >> success
>> >> > >> >> or
>> >> > >> >> failure of the command being tested. For example, if the
>> >> > >> >> operation is
>> >> > >> >> to
>> >> > >> >> delete a file, then you could test afterwards for its
>> >> > >> >> existence.
>> >> > >> >>
>> >> > >> >> > Perhaps you can help me if I put the entire script.
>> >> > >> >> > This is working for successful connections, but when the
>> >> > >> >> > connection
>> >> > >> >> > fails
>> >> > >> >> > or
>> >> > >> >> > bad username the log is recorded as success "Connected
>> >> > >> >> > to..."??!!
>> >> > >> >> >
>> >> > >> >> > Begin---------------------
>> >> > >> >> > cls
>> >> > >> >> > net use * /d /y
>> >> > >> >> >
>> >> > >> >> > Echo. Begin >log.txt
>> >> > >> >> > Echo. |date /T >>log.txt
>> >> > >> >> > Echo. |time /T >>log.txt
>> >> > >> >> > Echo. >>log.txt
>> >> > >> >>
>> >> > >> >> As an aside, I'd suggest doing this a bit differently:
>> >> > >> >>
>> >> > >> >> (
>> >> > >> >> Echo/ Begin
>> >> > >> >> Echo/ %date%
>> >> > >> >> Echo/ %time%
>> >> > >> >> Echo/
>> >> > >> >> ) >log.txt
>> >> > >> >>
>> >> > >> >> Using the DATE and TIME variables instead of the commands will
>> >> > >> >> allow
>> >> > >> >> them
>> >> > >> >> to
>> >> > >> >> appear on the same line:
>> >> > >> >>
>> >> > >> >> (
>> >> > >> >> Echo/ Begin at %time% on %date%
>> >> > >> >> Echo/
>> >> > >> >> ) >log.txt
>> >> > >> >>
>> >> > >> >> Also, "echo/" is marginally better than "echo.", however I
>> >> > >> >> can't
>> >> > >> >> quite
>> >> > >> >> remember why...
>> >> > >> >>
>> >> > >> >> > For /f "tokens=1,2,3" %%a in (ServerList.txt) do (
>> >> > >> >> > Echo Username Password ServerIP
>> >> > >> >> > Echo %%a %%b %%c
>> >> > >> >> >
>> >> > >> >> > Net use \\%%c %%b /User:%%a
>> >> > >> >> >
>> >> > >> >> > if %ErrorLevel% EQU 0 (
>> >> > >> >> > Echo Connected to %%c >>log.txt
>> >> > >> >> > Echo Connected to %%c
>> >> > >> >> > ) Else (
>> >> > >> >> > Echo Connection Failed for to %%c >>log.txt
>> >> > >> >> > Echo Connection Failed for to %%c
>> >> > >> >> > )
>> >> > >> >> > )
>> >> > >> >> > End Batch ---------------------
>> >> > >> >> >
>> >> > >> >> > Thank you
>> >> > >> >> >
>> >> > >> >> > "Pegasus (MVP)" wrote:
>> >> > >> >> >
>> >> > >> >> >>
>> >> > >> >> >> "Jmnts" <Jmnts[ at ]discussions.microsoft.com> wrote in message
>> >> > >> >> >> news:9EF692B8-8B62-468E-99AB-AA3A30A36C1A[ at ]microsoft.com...
>> >> > >> >> >> > Hi everyone
>> >> > >> >> >> >
>> >> > >> >> >> > I'm trying to do errorlevel handling but not with
>> >> > >> >> >> > expected
>> >> > >> >> >> > results:
>> >> > >> >> >> > Code:
>> >> > >> >> >> >
>> >> > >> >> >> > Net use \\%%a P[ at ]ssw0rd /User:mydomain\admin
>> >> > >> >> >> > IF NOT ERRORLEVEL 0 (
>> >> > >> >> >> > Echo. Connection Failed for to %%a
>> >> > >> >> >> > Echo. Connection Failed for to %%a >>Log.txt


Re: ERRORLEVEL
Jmnts 10/20/2008 8:05:02 AM
[Quoted Text]
>No, you are reading far too much into this. Sometimes a cigar is just a
>cigar, but in scripting "All" is *always* just an "All.


Correct. All is just All eheheh, nothing to worrie about... I just like to
know exactly what I'm doing and when things don't make sence tome I like to
try to understand it.

Thank you.


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen