How to start the system "beep" from the built-in computer speaker using a batch file?

I wrote a batch script interactively to perform some tasks.

Sometimes these tasks take a lot of time, and then the package asks if the user wants to go to the next task or return to the main menu of the package or ... etc.

Now I want to add the Interactive Alarm command, which will emit a small short beep (for example, the one that we turn on on our PCs) to alert the package user about new issues.

I don't know if this is possible or not, but the most important thing for me is NOT to use a GUI application like WMP or so. I just want to do this from the background, even if this sound signal should be made from a free speaker or using a third-party CLI application (by the way, I installed Cygwin on Win7-x64).

Please note that I will add this alarm command just before the interactive questions, waiting for the user's response to go to the next stage, so I canโ€™t just end the package with a real beep error!

So, someone please tell me how to do this?

I appreciate your help :)

+10
source share
5 answers

You cannot enter BEL directly into (for example) a notebook.

To get it, enter echo ^G>>yourbatch.bat on the command line (do not type ^ G , but <Control>-G , which will be displayed as ^G on the screen). This puts a weird looking character at the end of your file. This is a BEL 0x007 ("control-G") character. Just copy / move it to any echo command as you like. Also

 set /p "input=^Ggive value: " 

(where ^G represents a weird char)

+10
source
 rundll32.exe Kernel32.dll,Beep 750,300 

or

 rundll32.exe cmdext.dll,MessageBeepStub 

or

 rundll32 user32.dll,MessageBeep 

With rundll functions, you donโ€™t need special characters like ^G Using the first method, you can also set the frequency and time of the sound .

You can also check it out.

+21
source
 @echo off echo BEEP.BAT by CSS--- echo PRESS ANY KEY TO HEAR A BEEP... PAUSE>NUL ECHO echo I BEEPED PAUSE 

there is an ASCII ^ G control code after the echo. Just copy this code and save it as ASCII / ANSI using a text editor.

+1
source

use ECHO command to echo CTRL G

0
source

I think the best solution is to display the ^G file from the cmd command line, and then enter this file from the script, so you do not need to include control characters in the batch file itself:

 C:\> echo ^G>beep.snd 

Now in the "beep.snd" file there is an ASCII 007 character, then from the .bat file all you need to do is print it or copy it to the screen:

 type beep.snd 

or

 copy beep.snd con > nul 
0
source

Source: https://habr.com/ru/post/978547/


All Articles