Wikipedia:Reference desk/Archives/Computing/2018 September 7

Computing desk
< September 6 << Aug | September | Oct >> Current desk >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


September 7

edit

Beep in batch files

edit

I remember BEEP used to be a command in batch files.

Can I somehow ask a batch file to type the ASCII chr for the Bell character to produce a beep sound?

Many thanks,

Anna Frodesiak (talk) 04:07, 7 September 2018 (UTC)[reply]

Try typing the command: echo ^G
where the ^G is produced by holding down Ctrl and typing G. On Unix one may need to type Ctrl+V first to "quote" the ^G. DroneB (talk) 05:30, 7 September 2018 (UTC)[reply]
Hi DroneB. That works on the command line, but does not seem to work as a line in a batch. Anna Frodesiak (talk) 07:36, 7 September 2018 (UTC)[reply]
@Anna Frodesiak: It works for me. However the tricky part is putting the control character BEL into the shell script (i.e., your batch file). Are you talking about Windows environment? I managed to do that with a command-line command
echo echo ^G >> mybatch.cmd
The first echo is a command to output echo ^G line. That output is redirected with a double angle bracket combination so it gets appended at the end of mybatch.cmd. (WARNING: If you use a single > for redirection, the output of the echo command will overwrite the destination mybatch.cmd file, thus destroying its previous contents!)
That way I got a echo ^G line at the end of mybatch.cmd and was able to move it around (or even duplicate where necessary) within mybatch.cmd with a standard Notepad.
Similar trick works in Linux, altgough there you can simply input ^G during editing a script file with vi editor. --CiaPan (talk) 09:14, 7 September 2018 (UTC)[reply]
You lost me, CiaPan. I'm not that good at all of this and do not know what a .cmd file is. What would the line in the batch file look like? I'm using Win 10 by the way. Many thanks. Anna Frodesiak (talk) 10:26, 7 September 2018 (UTC)[reply]
Ah ok. anything .cmd is pretty much the same as .bat. Why even bring .cmd into it when .bat is fine? Anna Frodesiak (talk) 10:48, 7 September 2018 (UTC)[reply]
@Anna Frodesiak: You would have to ask Microsoft. The main historical difference is .bat files were used in DOS and early Windows by COMMAND.COM interpreter and .cmd were introduced in WindowsNT for cmd.exe interpreter. However, for backward compatibility, cmd.exe interprets .bat scripts as well. Some more information about technical differences between .bat and .cmd can be found in Batch file#Filename extensions section. --CiaPan (talk) 11:01, 7 September 2018 (UTC)[reply]
Fair enough. Thanks. Anna Frodesiak (talk) 11:07, 7 September 2018 (UTC)[reply]
So CiaPan, how to write that line in the batch file? Anna Frodesiak (talk) 11:07, 7 September 2018 (UTC)[reply]
@Anna Frodesiak: Try this: echo chr$7 which I just tried in a BAT file in my DOS computer. It didn't beep because this computer lacks the speaker and never makes any sounds, but the command wasn't rejected. Akld guy (talk) 22:07, 9 September 2018 (UTC)[reply]
Thanks, Akld guy. It seems typing echo chr$7 on the command line returns chr$7. I've sort of solved the thing using this teensy player:
c:
cd\"Program Files (x86)"\xmplay37
start xmplay.exe ding.WAV
TIMEOUT /T 1
taskkill /IM xmplay.exe
It's not pretty, but it works.
So, is it my imagination or was there once a BEEP command? Anna Frodesiak (talk) 22:23, 9 September 2018 (UTC)[reply]
In BASIC language the BEEP statement causes the PC speaker to play an 800 Hz tone for 0.25 seconds. It has the same effect as PRINT CHR$(7). DroneB (talk) 11:07, 10 September 2018 (UTC)[reply]
Oyoyoy. In some implementations of BASIC on some PCs, the command might exist and might do what you describe. But in other implementations of BASIC on PCs or other computers, it either does not exist, or does something else. And many environments nowadays allow you to specify what emitting ASCII \bel to the terminal will do, from nothing to just flashing the terminal background to playing any kind of fancy sound. --Stephan Schulz (talk) 20:05, 10 September 2018 (UTC)[reply]
IIRC in the old (really old) days, the ZX Spectrum dialect of Basic had a BEEP command, which allowed to define the pitch (as an integer offset in piano keys from C-major base) and duration... --CiaPan (talk) 10:30, 12 September 2018 (UTC)[reply]
The Spectrum was my first own computer (I had previously stolenborrowed my father's ZX81), and I think you specified frequency in Hertz and duration. But I may confuse this with Amstrad's Locomotive Basic... --Stephan Schulz (talk) 11:56, 12 September 2018 (UTC)[reply]
@Stephan Schulz: Found it: our Sinclair BASIC presents the table of keywords, and it confirms duration, pitch were parameters for BEEP.
What you recall above is most probably the Amstrad CPC's feature – the second paragraph in Locomotive BASIC#Features section mentions some advanced possibilities of Amstrad's SOUND command: ‘Many things, from selecting a particular channel or a combination of channels, setting envelopes, volume, pitch, noise, and so on could be done with a single SOUND command, with up to 7 parameters.’ --CiaPan (talk) 09:28, 13 September 2018 (UTC)[reply]
You are probably right - I remember from the Amstrad manual that 440Hz is A', and that going up or down an octave halves or doubles that frequency. --Stephan Schulz (talk) 06:14, 14 September 2018 (UTC)[reply]