Page 1 of 1

@echo off does not work for timeout [SOLVED]

Posted: 08 Jan 2023 11:15
by DOSadnie
So I have this script

Code: Select all

if not "%1" == "max" start /MAX cmd /c %0 max & exit/b
mode 1000

:: echo.                              Turning off monitors...
:: echo.                              
:: echo.                              PRESS ANY KEY TO CANCEL

@echo off
timeout /t 6 |findstr /r ".0$" && goto continue || exit
command > nul 2>&1

:continue
@echo off
powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int PostMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::PostMessage(-1,0x0112,0xF170,2)
that is suppose to turn my monitor after 6 seconds. And for 6 seconds it just flashes prompt sign in a full-screen CMD window. But then for a split second just before blackout it spits a text informing that it is waiting for 6 seconds.

Why is suddenly @echo off stopping to work? And how to mitigate that? I have also other scripts that have this problem

Re: @echo off does not work for timeout

Posted: 08 Jan 2023 11:33
by Lucky4Me
change
timeout /t 6 |findstr /r ".0$" && goto continue || exit
to
timeout /t 6 >nul |findstr /r ".0$" && goto continue || exit

Re: @echo off does not work for timeout

Posted: 10 Jan 2023 12:54
by jfl
I'd rather suggest:

Code: Select all

timeout /t 6 | findstr /r ".0$" >nul && goto continue || exit

Re: @echo off does not work for timeout

Posted: 13 Jan 2023 04:43
by DOSadnie
Lucky4Me wrote:
08 Jan 2023 11:33
[...]
timeout /t 6 >nul |findstr /r ".0$" && goto continue || exit
jfl wrote:
10 Jan 2023 12:54
[...]

Code: Select all

timeout /t 6 | findstr /r ".0$" >nul && goto continue || exit
They both seem to work

Thank you; problem solved

Re: @echo off does not work for timeout

Posted: 13 Jan 2023 06:28
by DOSadnie
DOSadnie wrote:
13 Jan 2023 04:43
[...]
problem solved
Well...

They do work for this particular script. But for this other script of mine with timeout

Code: Select all

chcp 65001 >nul

if not "%1" == "max" start /MAX cmd /c %0 max & exit/b
mode 1000

@echo off
echo.                                                                                                           Commencing system reset
echo.
echo.                                                                                                           PRESS ANY KEY TO CANCEL
echo.   

@echo off
timeout /t 3 |findstr /r ".0$" && goto continue || exit
command > nul 2>&1

:continue

cd "C:\Program Files Expanded\NirSoft\NirCmd\"
start "" nircmd.exe setdefaultsounddevice "Sound Blaster"

cd "C:\Program Files Expanded\NirSoft\NirCmd\Scripts\Audio\Volume"
start "" "Volume Level 20.lnk"

shutdown /r /f /t 0

X:\Acronis\M3-01
Y:\Acronis\M3-01

dir
this first version of that line

Code: Select all

timeout /t 6 >nul |findstr /r ".0$" && goto continue || exit 
breaks it [i.e. the reset of the system does not occur and the window of CMD just closes itself], while this second version

Code: Select all

timeout /t 6 | findstr /r ".0$" >nul && goto continue || exit
executes further the script but still with some text being flashed after the timeout ends

Re: @echo off does not work for timeout

Posted: 22 Jan 2023 09:15
by DOSadnie
DOSadnie wrote:
13 Jan 2023 06:28
DOSadnie wrote:
13 Jan 2023 04:43
[...]
problem solved
Well...

They do work for this particular script. But for this other script of mine with
[...]
Well, can anyone help me solve this second conundrum?

Re: @echo off does not work for timeout

Posted: 02 Jul 2023 05:07
by DOSadnie
I have tried using

Code: Select all

(timeout /t 6) | findstr /r ".0$" >nul && goto continue || exit
[i.e. enclosing timeout in parenthesis and added a pause sign before >>nul<<] but I still get a brief flashing of two lines with some text


I also tried adding

Code: Select all

@echo off
before every command / section- and then also a version where I made sure that it was used only once. And still I get some unwanted text

Re: @echo off does not work for timeout

Posted: 15 Jul 2023 03:13
by DOSadnie
What has worked for me [at lest in 3 out of 4 BAT file with multiple commands] was adding of

Code: Select all

>nul
at the end of almost each command; e.g.

Code: Select all

timeout /t 5 | findstr /R ".0$" >nul

As for using

Code: Select all

@echo off
in each case just one at the very beginning of whole script is sufficient