none
BATCH : Multiple Nested Loops "FOR /F ..." running well and stop after 355 times RRS feed

  • General discussion

  • Hello,

    I need to cath the résults of the command NSLOOKUP about IP and/or CNAME that come from our technical documentation and compare the values.
    My batch script is quiet complex and use "Multiple Nested Loops "FOR /F ..." " .
    And it's running very well, and after few minutes and write the first results (around 355 lines), the script stop.

    I don't use any command like SET xx=yy inside the loop.
    I use only text file.

    I add before each loop the command "setlocal ENABLEDELAYEDEXPANSION" and at the end of each loop "ENDLOCAL".

    But the loops stop.

    For the moment, I'm not an expert on PowerShell; and I prefer BATCH.
    What is you proposal ?

    Regards,

    • Changed type Bill_Stewart Friday, January 26, 2018 2:46 PM
    • Moved by Bill_Stewart Friday, January 26, 2018 2:46 PM Help vampire
    Tuesday, November 28, 2017 9:16 AM

All replies

  • You have exceeded a limit do to multiple embedded loops.  Use PowerShell to avoid this or redesign you code to not use embedded loops.


    \_(ツ)_/

    Tuesday, November 28, 2017 9:55 AM
  • Hello,
    It's quiet strange.
    I re-write my batch script entirely ...
    And I run it ...
    At the beginning , it's very quick...
    And at the middle, I mean during the read of the FILE_DNS_1.txt , the script is running slowly ...

    But it's not stopped ...it continues to run very slowly ...

    ---------------------------------------------------------------------------------------
    SCRIPT
    ---------------------------------------------------------------------------------------

    ::
    ECHO ON
    ::
    :: %pathDNS%\FILE_DNS_1.txt contain many CNAME (more than 500), like this format :
    :: ENVIRONMENT;HOSTNAME;CNAME1;CNAME2;CNAME3;
    :: %%a;%%b%%c;%%d;%%e;
    ::
    :: VARIABLE
    set pathDNS=D:\DNS
    ::
    ECHO ENVIRONMENT;HOSTNAME;CNAME;@IP > %pathDNS%\nslookup_Resultat.txt
    ::
    ::--CNAME1--
    FOR /F "tokens=1,3,4,5,6 delims=;" %%a IN (%pathDNS%\FILE_DNS_1.txt) DO (
    nslookup %%c > %pathDNS%\nslookup_temp1.txt
    FOR /F "tokens=1,2 delims=: skip=4" %%f IN (%pathDNS%\nslookup_temp1.txt) DO (
    ECHO %%a;%%b;%%c;%%g >> %pathDNS%\nslookup_Resultat.txt
    )
    )
    ::
    ::--CNAME2--
    FOR /F "tokens=1,3,4,5,6 delims=;" %%a IN (%pathDNS%\FILE_DNS_1.txt) DO (
    nslookup %%d > %pathDNS%\nslookup_temp3.txt
    FOR /F "tokens=1,2 delims=: skip=4" %%f IN (%pathDNS%\nslookup_temp3.txt) DO (
    ECHO %%a;%%b;%%d;%%g >> %pathDNS%\nslookup_Resultat.txt
    )
    )
    ::
    ::--CNAME3--
    FOR /F "tokens=1,3,4,5,6 delims=;" %%a IN (%pathDNS%\FILE_DNS_1.txt) DO (
    nslookup %%e > %pathDNS%\nslookup_temp5.txt
    FOR /F "tokens=1,2 delims=: skip=4" %%f IN (%pathDNS%\nslookup_temp5.txt) DO (
    ECHO %%a;%%b;%%e;%%g >> %pathDNS%\nslookup_Resultat.txt
    )
    )
    ::

    ---------------------------------------------------------------------------------------
    END
    ---------------------------------------------------------------------------------------

    I also spend more time to see what could be a loop in powershell :

    ---------------------------------------------------------------------------------------
    SCRIPT POWERSHELL
    ---------------------------------------------------------------------------------------

    set-executionpolicy unrestricted
     
    $content = Get-Content ".\cbEngine.ini" | foreach { $_ -replace "dudu","dada" }
    Set-Content -Path ".\cbEngine2.ini" -Value $content
     
    Write-Host "Press any key to continue ..."
    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

    ---------------------------------------------------------------------------------------
    END
    ---------------------------------------------------------------------------------------

    I need trainings on PowerShell ... I'm alone.






    • Edited by Cerkyr Tuesday, November 28, 2017 1:33 PM
    Tuesday, November 28, 2017 1:26 PM
  • Please read this first:

    This forum is for scripting questions rather than script requests

    It is good that you are trying to learn PowerShell, but we don't have the resources to train you in PowerShell or to translate ideas from batch into PowerShell code for you.


    -- Bill Stewart [Bill_Stewart]

    Tuesday, November 28, 2017 1:31 PM