Batch file failure under LE

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Oct 14, 2015
Hello all,

Got a brain bender here. I have a batch I wrote which is fairly simple. It loops through a set of servers and executes a command twice for each, counting the number of active and disconnected RDP sessions. This is done by using the @execstr function so I can set the output to variables. Then it outputs the info to screen.

The first version of the batch I did worked great in full TC but the loop seemed to fail to generate any output with LE on a new machine. All the functions I used are supported LE as far as I can see. The stopper seemed to be a IF command in the loop. Once the problematic IF line was reached, the steps after that point were not executed. It's as though the loop iterated again when it got to a problem.

So, I installed LE on my machine with the full TC installation and that copy of LE worked correctly too. It's as if part of the full install let the LE install work correctly. However, on a new machine with only LE, the batch fails. I had to shift over to using the @IF function for evaluations within the loop.

Success output (@if function used to do evaluations in the loop):

Failed output (if command used to do evaluations in the loop)

Anyone have an idea of what may be happening here?


David Wolfe



Scott Mintz
May 20, 2008
Solon, OH, USA
Keep in mind that FOR and IF are single line statements. So even though you have the FOR loop spread over multiple lines in the CMD file, it is executed as a single line. That means everything on the command line gets evaluated all at once. You are far better off using a DO loop.
@echo off

set servers=278 279 280
echo Gathering sessions data...
echo Citrix Servers: %servers

set dtotal=0
set atotal=0

DO i in /L %servers
    set disconnect=%@eval[%@execstr[query session /server:ahwctxinind%i >&> nul | find /c "Disc"] - 1]
    set active=%@execstr[query session /server:ahwctxinind%i >&> nul | find /c "Active"]
    set result=D = %disconnect `    ` A = %active
    iff %disconnect=-1 then
        set result=RDP Sessions Query Failed
        set disconnect=0
        set active=0
    echo Server ahwctxinind%i...... %result
    set dtotal=%@eval[%dtotal + %disconnect]
    set atotal=%@eval[%atotal + %active]

echo                      Total:   %dtotal`    `   %atotal
Oct 14, 2015
Thank you for the alternate approach, Scott! That does seem to universally work in TC and TC/LE. Had to adjust the = in the IFF statement to EQ but otherwise perfect. Still curious about why my original use of FOR was causing problems but I'll begin to favor DO loops now instead.