Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
DOSadnie
- Posts: 143
- Joined: 21 Jul 2022 15:12
- Location: Coding Kindergarten
#1
Post
by DOSadnie » 08 Jan 2023 11:15
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
Last edited by
DOSadnie on 15 Jul 2023 03:14, edited 2 times in total.
-
Lucky4Me
- Posts: 24
- Joined: 21 Oct 2020 06:33
#2
Post
by Lucky4Me » 08 Jan 2023 11:33
change
timeout /t 6 |findstr /r ".0$" && goto continue || exit
to
timeout /t 6 >nul |findstr /r ".0$" && goto continue || exit
-
jfl
- Posts: 226
- Joined: 26 Oct 2012 06:40
- Location: Saint Hilaire du Touvet, France
-
Contact:
#3
Post
by jfl » 10 Jan 2023 12:54
I'd rather suggest:
Code: Select all
timeout /t 6 | findstr /r ".0$" >nul && goto continue || exit
-
DOSadnie
- Posts: 143
- Joined: 21 Jul 2022 15:12
- Location: Coding Kindergarten
#4
Post
by DOSadnie » 13 Jan 2023 04:43
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
-
DOSadnie
- Posts: 143
- Joined: 21 Jul 2022 15:12
- Location: Coding Kindergarten
#5
Post
by DOSadnie » 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
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
Last edited by
DOSadnie on 22 Jan 2023 09:16, edited 1 time in total.
-
DOSadnie
- Posts: 143
- Joined: 21 Jul 2022 15:12
- Location: Coding Kindergarten
#6
Post
by DOSadnie » 22 Jan 2023 09:15
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?
-
DOSadnie
- Posts: 143
- Joined: 21 Jul 2022 15:12
- Location: Coding Kindergarten
#7
Post
by DOSadnie » 02 Jul 2023 05:07
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
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
-
DOSadnie
- Posts: 143
- Joined: 21 Jul 2022 15:12
- Location: Coding Kindergarten
#8
Post
by DOSadnie » 15 Jul 2023 03:13
What has worked for me [at lest in 3 out of 4 BAT file with multiple commands] was adding of
at the end of almost each command; e.g.
Code: Select all
timeout /t 5 | findstr /R ".0$" >nul
As for using
in each case just one at the very beginning of whole script is sufficient