Page 1 of 2

Timeout with GUI adjustments breaks its design after first second passes

Posted: 31 Jul 2023 16:09
by DOSadnie
I want to use timeout as a fail-safe so I should not make it silent thus I cannot hide it. But I also do not want to see the default
"Waiting for X seconds, press a key to continue...
message, where X is the digit informing about how many seconds are left


I managed to procure such script

Code: Select all

@echo off

echo. 
echo.   Info about what the script will do
echo.

setlocal

set "countdown=3"

echo.   Executing in:
echo.

for /L %%i in (%countdown%,-1,1) do (
    <nul set /p "=%%i "
    ping 127.0.0.1 -n 2 > nul
    cls
    echo.   Executing in:
    echo.

)

:: Here be dragons

echo.   The script has been executed
echo.
echo.   [Press any key to close this CMD window]
echo.

pause > nul
and it works half way

[Due to how QUOTE area works on this forum I am using >>_<< sign to represent >> << i.e. every underscore stands in for one white space]

Because it shows at step

#1
_
___Info about what the script will do

___Executing in:

3
[thus at the very beginning it works almost as intended by me as it only lacks three spaces before the digit]


#2
___Executing in:

2
[here it starts to break its envisioned visual design]


#3
___Executing in:

1

#4
___Executing in:

___The script has been executed

___[Press any key to close this CMD window]
_



I want it to show at step

#1
_
___Info about what the script will do

___Executing in:

___3

#2
_
___Info about what the script will do

___Executing in:

___2

#3
_
___Info about what the script will do

___Executing in:

___1

#4
_
___The script has been executed

___[Press any key to close this CMD window]
_


Does anyone know how to do that?

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 31 Jul 2023 17:12
by OJBakker
Use a for/L loop to do the countdown, and in the loop do the echoing for your message followed by an invisible timeout /T 1. And with invisible I mean suppress the output of timeout with >nul.

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 01 Aug 2023 12:07
by DOSadnie
Thank you for the idea

I managed to come up with this version

Code: Select all

@echo off

echo.
echo.   Info about what the script will do
echo.

setlocal

set "countdown=3"

echo.   Executing in:
echo.

for /l %%i in (%countdown%,-1,1) do (
    cls
    echo.
    echo.   Info about what the script will do
    echo.
    echo.   Executing in:
    echo.
    echo.   %%i
    timeout /t 1 >nul
)

cls

:: Here be dragons
::
:: Use >nul to hide them

echo.
echo.   The script has been executed
echo.
echo.   [Press any key to close this CMD window]
echo.

pause > nul
which does exactly what I need it to do - with the caveat of the CMD window being reloaded each second thus annoyingly flashing

And this version does not flash

Code: Select all

@echo off

setlocal enabledelayedexpansion

echo.
echo.   Info about what the script will do
echo.

set "countdown=3"

echo.   Executing in:
echo.

for /l %%i in (%countdown%,-1,1) do (
    <nul set /p "=   %%i   "
    timeout /t 1 >nul
)

cls

:: Here be dragons
::
:: Use >nul to hide them

echo.
echo.   The script has been executed
echo.
echo.   [Press any key to close this CMD window]
echo.

pause > nul
but keeps adding each following digit on the right side of the previous one and I was not able to add three white spaces before the first one i.e. resulting with
___Info about what the script will do

___Executing in:

3___2___1
before
___The script has been executed

___ [Press any key to close this CMD window]
is shown

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 01 Aug 2023 22:00
by Batcher
test-1.bat

Code: Select all

@echo off
for /f %%i in ('echo prompt $H ^| cmd') do (
    set "KeyBS=%%i"
)
echo   Executing in:
for /l %%i in (3,-1,1) do (
    set /p "= %KeyBS%  %%i"<nul
    set /p "=%KeyBS%%KeyBS%%KeyBS%"<nul
    timeout /t 1 >nul
)
echo,
echo   The script has been executed
pause

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 01 Aug 2023 23:18
by Aacini
Mmm... Perhaps I don't understand your request...

However, if you want to move the cursor to a previous line, you can do it via this trick...

Antonio

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 05 Aug 2023 04:15
by DOSadnie
Batcher wrote:
01 Aug 2023 22:00
test-1.bat
[...]
This works, thank you

It shows
Executing in:
__X
__The script has been executed


I tried to improve it visually by making it to show
Executing in:

______X

__The script has been executed
but this version

Code: Select all

@echo off
setlocal enabledelayedexpansion

for /f %%i in ('echo prompt $H ^| cmd') do (
    set "KeyBS=%%i"
)

echo   Executing in:
for /l %%i in (3,-1,1) do (
    set "spaces="
    for /l %%j in (1,1,%%i) do (
        set "spaces=!spaces!     "
    )
    echo !spaces!!KeyBS!  %%i
    echo %KeyBS%%KeyBS%%KeyBS%
    timeout /t 1 >nul
)
echo.
echo   The script has been executed
pause
shows in the end
Executing in:

__________________3

____________2

______1

The script has been executed
while this version

Code: Select all

@echo off
setlocal enabledelayedexpansion

for /f %%i in ('echo prompt $H ^| cmd') do (
    set "KeyBS=%%i"
)

echo   Executing in:
echo.
for /l %%i in (3,-1,1) do (
    set "spaces="
    for /l %%j in (1,1,%%i) do (
        set "spaces=!spaces!     "
    )
    set /a "numspaces=(3-%%i)*5"
    set "sp=!spaces:~0,!numspaces!"
    echo !sp!!KeyBS!  %%i
    echo %KeyBS%%KeyBS%%KeyBS%
    timeout /t 1 >nul
)
echo.
echo   The script has been executed
pause
produces in the end
__Executing in:

numspace 3

numspace 2

numspace 1


__The script has been executed

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 13 Oct 2023 10:18
by DOSadnie
Due to not being able to come up with a properly working BAT, I decided to use this PS1 script instead

Code: Select all

Write-Host "Line of text at the very top"
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host "Line of text in the middle"
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host "Last line of text"
Write-Host

$SHOWING_OF_CURSOR_ON_TOP_PREVENTION = [System.Console]::CursorTop

# Number of seconds
3..0 | `

ForEach-Object `
 {
        [System.Console]::SetCursorPosition(0, $SHOWING_OF_CURSOR_ON_TOP_PREVENTION)
        
        if ($_ -eq 3)   # Showcase of the first digit / second
    {
    Write-Host
    Write-Host
    Write-Host "   Executing in"
    Write-Host
    Write-Host -ForegroundColor Red "    ► $_ ◄"
    Write-Host " "
    Write-Host "   seconds"
    Write-Host
    }
    
        else   # Showcase of the remaining digits / seconds
    {
    Write-Host
    Write-Host
    Write-Host "   Executing in"
    Write-Host
    Write-Host -ForegroundColor Red "    ► $_ ◄"
    Write-Host " "
    Write-Host "   seconds"
    Write-Host
    }

    Start-Sleep -Seconds 1
    
    Write-Host " `b"

}

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 13 Oct 2023 18:33
by Aacini
What about this?

Code: Select all

@echo off

cls
echo/ 
echo    Info about what the script will do
echo/

setlocal EnableDelayedExpansion

rem Get an ASCII CR (13) character
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"
rem Create a file with *just* 3 spaces
call :CreateSpacesFile 3

set "countdown=3"

echo    Executing in:
echo/

for /L %%i in (%countdown%,-1,1) do (
    type SpacesFile.txt
    <nul set /p "=%%i!CR!"
    ping 127.0.0.1 -n 2 > nul
)

:: Here be dragons

echo    The script has been executed
echo/
echo    [Press any key to close this CMD window]
echo/

pause > nul
goto :EOF



:CreateSpacesFile numOfSpaces
setlocal EnableDelayedExpansion
set "spcs="
for /L %%i in (1,1,%1) do set "spcs=!spcs! "
set /P ^"=X^
% Do not remove this line %
%spcs%^" > spacesFile.tmp < nul
findstr /V "X" spacesFile.tmp > spacesFile.txt
del spacesFile.tmp
exit /B
Antonio

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 14 Oct 2023 07:05
by DOSadnie
It produces

Code: Select all

   Info about what the script will do

   Info Executing in:

   Info 3The   2The   1The   The script has been executed

   Info [Press any key to close this CMD window]
and leaves that spacesFile.txt file behnd

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 14 Oct 2023 08:08
by DOSadnie
I also just now tried going back [viewtopic.php?f=3&t=10871&p=69159#p68888] and after all settling on seeing

Code: Select all

    3     2     1
But I get

Code: Select all

3  2  1
with this script utilizing the >>set<< trick

Code: Select all

@echo off

setlocal enabledelayedexpansion

echo.
echo.   Info about what the script will do
echo.

set "countdown=3"

echo.   Executing in:
echo.

chcp 65001 >nul

set "PAUSES_A=   "
set "PAUSES_B="

for /l %%i in (%countdown%,-1,1) do (
    <nul set /p=!PAUSES_A! %%i !PAUSES_B!
    timeout /t 1 >nul
    )

:: Here be dragons
::
:: Use >nul to hide them

echo.
echo.   The script has been executed
echo.
echo.   [Press any key to close this CMD window]
echo.

pause > nul
despite adding to it

Code: Select all

chcp 65001 >nul
before using various white spaces from the list available at https://en.wikipedia.org/wiki/Whitespace_character [although I have not tested out all of them]


But the minute I make a change like for example this one

Code: Select all

set "PAUSES_A=.   "
set "PAUSES_B=; "
what I will get is this

Code: Select all

   Info about what the script will do

   Executing in:

.    3 ; .    2 ; .    1 ;
   The script has been executed

   [Press any key to close this CMD window]

So the problem, with this version, is that any number of leading white spaces are ignored i.e. not displayed; and adding back quotes for that crucial line does not help either

But as I said I already have went with using PS1, as apparently [as the version from this post also shows] BAT scripting is rather too basic to achieve such GUI elementrs

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 14 Oct 2023 12:07
by Aacini
DOSadnie wrote:
14 Oct 2023 07:05
It produces

Code: Select all

   Info about what the script will do

   Info Executing in:

   Info 3The   2The   1The   The script has been executed

   Info [Press any key to close this CMD window]
and leaves that spacesFile.txt file behnd

It works perfectly here:

#1

Code: Select all


   Info about what the script will do

   Executing in:

   3
#2

Code: Select all


   Info about what the script will do

   Executing in:

   2
#3

Code: Select all


   Info about what the script will do

   Executing in:

   1
#4

Code: Select all


   Info about what the script will do

   Executing in:

   The script has been executed

   [Press any key to close this CMD window]
Windows 10 here

Are you sure you copied the Batch file as it is?

Just add a del spacesFile.txt at end...

Antonio

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 16 Oct 2023 10:56
by DOSadnie
Yes, I am sure; this is the code cut out from UTF-8 BAT file saved on my volume

Code: Select all

@echo off

cls
echo/
echo    Info about what the script will do
echo/

setlocal EnableDelayedExpansion

rem Get an ASCII CR (13) character
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"
rem Create a file with *just* 3 spaces
call :CreateSpacesFile 3

set "countdown=3"

echo    Executing in:
echo/

for /L %%i in (%countdown%,-1,1) do (
    type SpacesFile.txt
    <nul set /p "=%%i!CR!"
    ping 127.0.0.1 -n 2 > nul
)

:: Here be dragons

echo    The script has been executed
echo/
echo    [Press any key to close this CMD window]
echo/

pause > nul
goto :EOF

:CreateSpacesFile numOfSpaces
setlocal EnableDelayedExpansion
set "spcs="
for /L %%i in (1,1,%1) do set "spcs=!spcs! "
set /P ^"=X^
% Do not remove this line %
%spcs%^" > spacesFile.tmp < nul
findstr /V "X" spacesFile.tmp > spacesFile.txt
:: del spacesFile.tmp
@echo off

cls
echo/
echo    Info about what the script will do
echo/

setlocal EnableDelayedExpansion

rem Get an ASCII CR (13) character
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"
rem Create a file with *just* 3 spaces
call :CreateSpacesFile 3

set "countdown=3"

echo    Executing in:
echo/

for /L %%i in (%countdown%,-1,1) do (
    type SpacesFile.txt
    <nul set /p "=%%i!CR!"
    ping 127.0.0.1 -n 2 > nul
)

:: Here be dragons

echo    The script has been executed
echo/
echo    [Press any key to close this CMD window]
echo/

pause > nul
goto :EOF

:CreateSpacesFile numOfSpaces
setlocal EnableDelayedExpansion
set "spcs="
for /L %%i in (1,1,%1) do set "spcs=!spcs! "
set /P ^"=X^
% Do not remove this line %
%spcs%^" > spacesFile.tmp < nul
findstr /V "X" spacesFile.tmp > spacesFile.txt
del spacesFile.tmp
del spacesFile.txt
exit /B
And now, after adjusting its end, I get

Code: Select all

   Info about what the script will do

   Executing in:

The system cannot find the file specified.
3TheThe system cannot find the file specified.
2TheThe system cannot find the file specified.
1The   The script has been executed

   [Press any key to close this CMD window]

   Executing in:

The system cannot find the file specified.
3TheThe system cannot find the file specified.
2TheThe system cannot find the file specified.
1The   The script has been executed

   [Press any key to close this CMD window]
i.e. doubled run, because when after seeing [the first] "Press any key to close this CMD window" I do press any key, the whole shebang is executed once more in the same CMD window

I am using Windows 10 Enterprise 20H2 x64

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 16 Oct 2023 12:59
by Aacini
Aacini wrote:
14 Oct 2023 12:07

Are you sure you copied the Batch file as it is?

Antonio
DOSadnie wrote:
16 Oct 2023 10:56
Yes, I am sure...

Mmmm... The script I posted have 47 lines. These are the last ones:

Code: Select all

38::CreateSpacesFile numOfSpaces
39:setlocal EnableDelayedExpansion
40:set "spcs="
41:for /L %%i in (1,1,%1) do set "spcs=!spcs! "
42:set /P ^"=X^
43:% Do not remove this line %
44:%spcs%^" > spacesFile.tmp < nul
45:findstr /V "X" spacesFile.tmp > spacesFile.txt
46:del spacesFile.tmp
47:exit /B
The script you posted have 90 lines! :shock: Apparently, it have my code repeated two times. This is the same section in your code:

Code: Select all

36::CreateSpacesFile numOfSpaces
37:setlocal EnableDelayedExpansion
38:set "spcs="
39:for /L %%i in (1,1,%1) do set "spcs=!spcs! "
40:set /P ^"=X^
41:% Do not remove this line %
42:%spcs%^" > spacesFile.tmp < nul
43:findstr /V "X" spacesFile.tmp > spacesFile.txt
44::: del spacesFile.tmp
45:@echo off
46:
47:cls
If you remove the exit /B command that appear in my script at line 47, you are modifying the code in a way that it don't correctly works anymore... :cry:

Antonio

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 22 Oct 2023 08:57
by DOSadnie
My fingers slipped and I performed a double pastng of what I had in the clipboard at that time

This is the code I have

Code: Select all

@echo off

cls
echo/
echo    Info about what the script will do
echo/

setlocal EnableDelayedExpansion

rem Get an ASCII CR (13) character
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"
rem Create a file with *just* 3 spaces
call :CreateSpacesFile 3

set "countdown=3"

echo    Executing in:
echo/

for /L %%i in (%countdown%,-1,1) do (
    type SpacesFile.txt
    <nul set /p "=%%i!CR!"
    ping 127.0.0.1 -n 2 > nul
)

:: Here be dragons

echo    The script has been executed
echo/
echo    [Press any key to close this CMD window]
echo/

pause > nul
goto :EOF



:CreateSpacesFile numOfSpaces
setlocal EnableDelayedExpansion
set "spcs="
for /L %%i in (1,1,%1) do set "spcs=!spcs! "
set /P ^"=X^
% Do not remove this line %
%spcs%^" > spacesFile.tmp < nul
findstr /V "X" spacesFile.tmp > spacesFile.txt
findstr /V "X" spacesFile.tmp > spacesFile.txt
del spacesFile.tmp
del spacesFile.txt
exit /B
and it produces

Code: Select all

   Info about what the script will do

   Executing in:

The system cannot find the file specified.
3TheThe system cannot find the file specified.
2TheThe system cannot find the file specified.
1The   The script has been executed

   [Press any key to close this CMD window] 

Re: Timeout with GUI adjustments breaks its design after first second passes

Posted: 18 Nov 2023 11:12
by DOSadnie
I have managed to produce

Code: Select all

   Info about what the script will do

   Executing in:

     3
    2
   1
   The script has been executed

   [Press any key to close this CMD window]
with this version

Code: Select all

@echo off

cls
echo/
echo    Info about what the script will do
echo/

setlocal EnableDelayedExpansion

set "countdown=3"

echo    Executing in:
echo/

for /L %%i in (%countdown%,-1,1) do (
    set "spcs="
    for /L %%j in (1,1,%%i) do set "spcs=!spcs! "
    echo   !spcs!%%i
    ping 127.0.0.1 -n 2 > nul
)

:: Here be dragons

echo    The script has been executed
echo/
echo    [Press any key to close this CMD window]
echo/

pause > nul
goto :EOF