Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Batch file failure under LE

Oct
29
0
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?

Thanks!

David Wolfe
 

Attachments

  • Demo - Does not Work in LE does in Full.cmd
    708 bytes · Views: 354
  • Demo - Works in LE.cmd
    757 bytes · Views: 310
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.
Code:
@echo off

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

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
    endiff
   
    echo Server ahwctxinind%i...... %result
    set dtotal=%@eval[%dtotal + %disconnect]
    set atotal=%@eval[%atotal + %active]
enddo

echo.
echo                      Total:   %dtotal`    `   %atotal
echo.
 
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.
 

Similar threads

Back
Top