Play default beep in Win 10 batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dosnovice
Posts: 2
Joined: 22 Jul 2016 07:07

Play default beep in Win 10 batch

#1 Post by dosnovice » 22 Jul 2016 07:24

I have a test.bat file with only
Echo ^G
Running the file in a command prompt plays the beep but not if I run it via a desktop shortcut.
I guess I need some additional commands for Win10. Any help is appreciated.

Thanks

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Play default beep in Win 10 batch

#2 Post by Squashman » 22 Jul 2016 07:41

Unfortunately I cannot test out the new features of Windows 10 console. But you could just use the old fashion way of using the Beep.
viewtopic.php?t=5860

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Play default beep in Win 10 batch

#3 Post by penpen » 22 Jul 2016 16:49

dosnovice wrote:I have a test.bat file with only
Echo ^G
Running the file in a command prompt plays the beep
I couldn't get the script to work this way on my win 10:
Have you changed any cmd property?


penpen

dosnovice
Posts: 2
Joined: 22 Jul 2016 07:07

Re: Play default beep in Win 10 batch

#4 Post by dosnovice » 23 Jul 2016 17:58

From a command prompt I wrote

copy con test.bat
echo ^G (i.e. press CTRL G)
press Ctrl Z to end batch file.

Then run test

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Play default beep in Win 10 batch

#5 Post by penpen » 24 Jul 2016 04:27

Then the content is not:

Code: Select all

echo ^G
The "^G" is just a cmd.exe replacement string for the control sequence CTRL+G:
Although easy to understand, you should have mention why you've written it this way in your OP.
I've discarded this ctrl sequence within the file, because no text editor will show it this way.
But most probable it will be shown as an empty sqare, or a question mark.

The reason why you don't hear anything, when running this bat via shortcut is simple:
The console window starts a task, that plays the sound, but there is not enough time to hear the sound,
because the console window closes immediately after it has displayed the glyphs (killing all subtasks).

Use something like (where BEL is the bell character 0x07):

Code: Select all

echo BEL
timeout 2


penpen

Edit: Corrected "most possible" to "most probable".
Edit 2: Corrected a flaw.
Last edited by penpen on 25 Jul 2016 15:41, edited 2 times in total.

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Play default beep in Win 10 batch

#6 Post by thefeduke » 25 Jul 2016 14:38

penpen wrote: no text editor will show it this way.
But most possible it will be shown as an empty sqare, or a question mark.

For example, within my particular editor it shows as a large round dot, but a screen print within that editor shows the record like this:

Code: Select all

---------------------------------------------------------------------------------------
000001 Echo                                                                          
       46662022222222222222222222222222222222222222222222222222222222222222222222222222
       538F0700000000000000000000000000000000000000000000000000000000000000000000000000
---------------------------------------------------------------------------------------
The 0x07 shows as a blank in Dostips Forum Post Preview, and so I expect in the post, but the interesting part is that it shows as an empty square in the editor used in the forum software to compose the post. I expect that a quote of my post here would reveal the empty box again.

Here are the important bytes from the above codebox:

Code: Select all

Echo 
These six bytes can be copied from this post to a DOS Prompt, even though byte six appears invisible, to make noise or they can be copied to your editor of choice.

John A.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Play default beep in Win 10 batch

#7 Post by penpen » 25 Jul 2016 17:46

@thefeduke, and all who mght be interested. (although offtopic, i think)

Just for information:
The different visualizations of that ctrl-character depends on the definition used (sounds abstract).

The "large round dot" is mostly used by old(er) applications using this definition of cp 437, 850, ... (for example under MS-DOS 6.22):
https://de.wikipedia.org/wiki/Codepage_437

Btw: Your "screen print" is looking really strange:
What editor did you use?


Nowadays, this definition of cp 437, 850, ... is in use:
https://msdn.microsoft.com/en-us/goglobal/cc305156

There you see, that ANSI character 0x07 is mapped to U+0007.
The (more or less) funny thing is this is mostly not rendered as defined by unicode.org
(because the the method of truetype fonts, to use the ".notdef" glyph if a character cannot be rendered, is older).

Unicode org has defined to use no glyph because it is a ctrl character (=="invisible" width=height=0; but it still is there and could be copied).
If you want to force displaying this character you have to use the REPLACEMENT CHARACTER:
http://unicode.org/cldr/utility/character.jsp?a=0007
But actual use is: Only use this glyph to display errors in stream/coding/... (this is more helpfull, when analyzing streams).

=> When using fonts typically the ".notdef" glyph is used, which is recommended to be a vertical rectangle (== "empty square in the editor ..."), a vertical rectangle containing a question mark, and a vertical rectangle with diagonals.
(The first two glyphs have been implemented for most TTF's i have seen, so: "most probable" ... not the flaw i've first written: "most possible")
But nevertheless the glyph could be any for example a whitespace (== "blank" - i assume).

Might be confusing on a first look, but is pretty usefull.
(I also recommend not to use ctrl characters in forums, better use the old shortcuts: NUL, SOH, ... BEL, ... .

penpen

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Play default beep in Win 10 batch

#8 Post by foxidrive » 25 Jul 2016 22:20

dosnovice wrote:I have a test.bat file with only
Echo ^G
Running the file in a command prompt plays the beep but not if I run it via a desktop shortcut.
I guess I need some additional commands for Win10. Any help is appreciated.

Thanks


Control G was reliable in the MSDOS days and an alternate method today is scripting a media player like VLC to play an MP3 file with the sound you want inside.

Windows has many sounds in the Media folder in the Windows directory that you can choose from.

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Play default beep in Win 10 batch

#9 Post by thefeduke » 26 Jul 2016 01:40

penpen wrote:Use something like (where BEL is the bell character 0x07):
Thank you for the catalog of background sources. So, BEL seems to be an example of an accepted shorthand from these tables in this world of what you don't see is what you get. Aside: I remember going "online" with a CMC Selectric typewriter, telephone and 50b acoustic coupler. Now I can visualize a Magnetic Card full of characters and these codes that caused mechanical movement in the typewriter.

penpen wrote:Btw: Your "screen print" is looking really strange:
What editor did you use?
I used a line editor, called SPFlite http://spflite.com, that can toggle a plain or hex display. The application copies the displayed text (not a screen image) to the clipboard, from which I selected one line for my post.

John A.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Play default beep in Win 10 batch

#10 Post by Squashman » 26 Jul 2016 06:19

thefeduke wrote:]I used a line editor, called SPFlite http://spflite.com, that can toggle a plain or hex display. The application copies the displayed text (not a screen image) to the clipboard, from which I selected one line for my post.

John A.

SWEET. Did not know this existed. Been a mainframe user for 20 years and always wanted some of the features that most Windows text editors did not have.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Play default beep in Win 10 batch

#11 Post by penpen » 26 Jul 2016 06:59

thefeduke wrote:So, BEL seems to be an example of an accepted shorthand from these tables in this world of what you don't see is what you get.
Yes, and no.
If writing in a (non source code) text, or in a source code comment, then BEL is a valid (and one of the well known) name for this character.

But in source code (no comment) it is not valid:
You have to add the information, that this should be interpreted as the bell character via additional text (or comment) like 'where BEL is the bell character 0x07', or 'let "BEL" be the BEL', ....
If there is no such information, then BEL is just the sequence of characters 'B', 'E', 'L'.

So you could also use "echo ^G", but you have to add the information, that "^G" is the BEL (bell character, 0x07, ...).
If there is no such information, then "^G" is just a sequence of the characters '^', 'G'.

Information could also be well known in different contexts, so if typing ^G into the console window of cmd.exe, then it might be the bell character;
see my second post, why i've assumed, that this is not the case (this time, so i've assumed '^'; 'G').

It may sound like i am very particular about this, but here a new behaviour/feature is addressed here.
One had to guess which one of these:
- new cmd.exe behavior interpreting "^G" as BEL
- treat shortcut calls of bat files in a different way, then calling bat from within command line context,
- playing ping in another way
- ...
In addition dosnovice understood that one have guessed wrong and added the missing detail,
so i think this my sight is not too unusual.

thefeduke wrote:SPFlite http://spflite.com
Thanks, it sounds interesting, so i'll test it, too.


penpen

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Play default beep in Win 10 batch

#12 Post by npocmaka_ » 16 Sep 2016 16:54

Code: Select all

rundll32.exe cmdext.dll,MessageBeepStub
rundll32 user32.dll,MessageBeep


but the sound sounds different from echo ^G (but I'm not sure)

Post Reply