performancebatch-filereducing

Batch: Slowing processing speed


I am creating a little project to impress my friends, and was curious on how I could slow down the text outflow on the program, using just one line.

I am having a problem (And trust me, I did my research), and was curious as to how to slow down the batch processing speed in general, without doing echo hi TIMEOUT 5>nul echo hi again, etc. But instead, only a single line at the beginning, which slows the output of the text for the whole batch script. Thanks!


Solution

  • The only real way to do this in the batch language would be to use the call command to call a function and to work. This can be placed at the bottom of your batch document.

    Furthermore, Since your not real clear on your goal here & from reading the comments, I'm going to assume that from echo hi & TIMEOUT 5>nul echo hi again you want to display each line after 5 seconds BUT from just one line or command. This can be done easily with call & an FOR loop. In this case we can use %* to gather all "Words Line One", "Words Line Two" that you wish.

    Combining this with simple syntax-replacement to remove the quotes and we good.

    DelayedLine.bat

    @echo off
    @setlocal EnableDelayedExpansion
    
    Rem | To use the command, Call :SlowOutput "Desired Line" "Desired Line" "Desired Line"
    
    Call :SlowOutput "Line Number One" "Line Number Two" "Line Number Three"
    
    pause>nul
    Goto :EOF
    
    :SlowOutput
    for %%A in (%*) do (
    
        Set "String=%%A"
        Set String=!String:"=%!
    
        echo !String!
    
        Rem | Change 5 To How Many (Seconds) You Wish
        Timeout 5 /NoBreak>Nul
    )
    goto :EOF
    

    If your goal was to have a typewrighter effect, we can use a script by hackoo on this thread here and modify it to work with the call in an organized matter.

    This script will display letter by letter and for each call "Word" "Word" new quote a new line. All working by one line via call

    LetterDelay.bat

    @echo off
    
    Rem | To use the command, Call :SlowText "Desired Text"
    Rem | To combine two "echo's" on one line we can use the "&"
    
    Call :SlowText "Hello!" & Call :SlowText "How is your day today?"
    
    pause>nul
    Goto :EOF
    
    :SlowText
    (
    echo strText=wscript.arguments(0^)
    echo intTextLen = Len(strText^)
    
    echo intPause = 100
    echo For x = 1 to intTextLen
    echo     strTempText = Mid(strText,x,1^)
    echo     WScript.StdOut.Write strTempText
    echo     WScript.Sleep intPause
    echo Next
    
    )>%tmp%\%~n0.vbs
    @cScript.EXE /noLogo "%tmp%\%~n0.vbs" "%~1"
    
    Rem | echo. is optional. It's used as a constant for a newline \n
    echo.
    goto :EOF
    

    For help on any of the commands do the following: