Is There A Quicker Way To Make The BEEP Sound In Batch?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nitt
Posts: 218
Joined: 22 Apr 2011 02:43

Is There A Quicker Way To Make The BEEP Sound In Batch?

#1 Post by nitt » 31 May 2011 17:18

Is There A Quicker Way To Make The BEEP Sound In Batch?

The only way I know of how to make the BEEP sound is by echoing the BELL character, which is Ascii number 7. Since I can't exactly type the BELL character, I wrote a quick script to retrieve it for me:

Code: Select all

@echo off
echo wscript.echo(chr(7)) > ~tmp.vbs
for /f %%a in ('cscript ~tmp.vbs') do (set beep=%%a)
del ~tmp.vbs
echo %beep%
pause


This sets the variable "beep" to the bell. Now if I echo "%beep%" it will make the BEEP noise.

I was thinking of just making a BEEP command in C++, but I wanted to do it without using any commands other than the built-in ones.

And also if you can provide a way to use this without using a TEMP file. That would help.

Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Re: Is There A Quicker Way To Make The BEEP Sound In Batch?

#2 Post by Cleptography » 31 May 2011 17:23

Good question, never really messed around with the sounds in win, I know of the vbscript way you have displayed, I know autoit can do this easily.

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Is There A Quicker Way To Make The BEEP Sound In Batch?

#3 Post by orange_batch » 31 May 2011 17:26

echo:

(bullet character)

Ctrl+G in Command Prompt to type it.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Is There A Quicker Way To Make The BEEP Sound In Batch?

#4 Post by dbenham » 31 May 2011 17:30

nitt wrote:Since I can't exactly type the BELL character, I wrote a quick script to retrieve it for me:

You can type the BELL character. Simply press <Ctrl>G (hold down control key and press G). Alternatively you can hold down the <Alt> key and type 007 on the numeric key pad. The <Alt> method words for any char value betwee 1-255. If you can't get this directly in your editor, you can do it in a command window and echo the value to a file. Your editor should be able to work with it there.

Dave Benham

nitt
Posts: 218
Joined: 22 Apr 2011 02:43

Re: Is There A Quicker Way To Make The BEEP Sound In Batch?

#5 Post by nitt » 31 May 2011 17:31

orange_batch wrote:echo:

(bullet character)

Ctrl+G in Command Prompt to type it.


Oh, that works. xP

-T-h-a-t-w-o-u-l-d-b-e-A-l-t-+-7-,-I-'-m-s-o-d-u-m-b-.-A-l-t-c-o-d-e-s-a-r-e-A-s-c-i-i-.-

I just checked and echoing the bullet character doesn't seem to work in a Batch script... Mine works still, though. :/

Also I just checked Ctrl+G also gets you the bullet character. So type in "echo" then press Ctrl+G and press enter and it beeps.
Last edited by nitt on 31 May 2011 17:35, edited 2 times in total.

Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Re: Is There A Quicker Way To Make The BEEP Sound In Batch?

#6 Post by Cleptography » 31 May 2011 17:31

Learn something new everyday.
Nice trick.

Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Re: Is There A Quicker Way To Make The BEEP Sound In Batch?

#7 Post by Cleptography » 31 May 2011 17:32

Now is there a way in batch that can control the frequency like in autoit?

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Is There A Quicker Way To Make The BEEP Sound In Batch?

#8 Post by orange_batch » 31 May 2011 17:34

No.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Is There A Quicker Way To Make The BEEP Sound In Batch?

#9 Post by Ed Dyreen » 31 May 2011 17:40

:lol: :lol: XP .CMD &.BAT compatible :!: :!:

Code: Select all

CSOUND 523 659 523 659 523
CSOUND 1046 1318 1046
CSOUND 220(2) 294(4)
CSOUND 1046,2093,1318,2637,1568,3136,2093,4186(4)
CSOUND 4186,2093,3136,1568,2637,1318,2093,1046(4)
CSOUND 523 0(17) 523 0(17) 523 0(17) 523 0(17) 1046(6)


It is com of 1kb, if u tell me how, I decompile it for u with debug, so I can post the ASM code :!:
Last edited by Ed Dyreen on 31 May 2011 18:14, edited 2 times in total.

nitt
Posts: 218
Joined: 22 Apr 2011 02:43

Re: Is There A Quicker Way To Make The BEEP Sound In Batch?

#10 Post by nitt » 31 May 2011 17:43

Ed Dyreen wrote::lol: :lol: XP compatible :!: :!:

Code: Select all

CSOUND 523 659 523 659 523
CSOUND 1046 1318 1046
CSOUND 220(2) 294(4)
CSOUND 1046,2093,1318,2637,1568,3136,2093,4186(4)
CSOUND 4186,2093,3136,1568,2637,1318,2093,1046(4)
CSOUND 523 0(17) 523 0(17) 523 0(17) 523 0(17) 1046(6)


It is com of 1kbs, if u tell me how, I decompile it for u with debug, so I can post the ASM code :!:


CSOUND? That's on XP? I've never heard of that command...
DEBUG also isn't on my 64bit. :<

I wanted to be able to write COM files from the console but there wasn't DEBUG, so I wrote COMWRITER. If you care to see that PM me.
Last edited by nitt on 31 May 2011 17:45, edited 1 time in total.

Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Re: Is There A Quicker Way To Make The BEEP Sound In Batch?

#11 Post by Cleptography » 31 May 2011 17:45

we can do it like this to

Code: Select all

Program Beep;

 uses CRT;

 var Tone,Duration: Word;
         Check: Integer;

begin
 if ParamCount<=2 then
                                   begin
                                        Writeln;
                                        Writeln ('BEEP Frequency Duration');
                                        Writeln;
                                        Writeln ('   Frequency - Hz');
                                        Writeln ('   Duration  - mS');
                                        Writeln;
                                        Tone:=800;
                                        Duration:=1000;
                                   end
                                  else
                                   begin
                                        VAL (ParamStr(1),Tone,Check);
                                        VAL (ParamStr(2),Duration,Check);
                                   end;
 Sound (Tone);
 Delay (Duration);
 NoSound;
end.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Is There A Quicker Way To Make The BEEP Sound In Batch?

#12 Post by Ed Dyreen » 31 May 2011 17:49

What is the command? I really don't know?

Don't remember, we use it sometimes when debugging ???

CSOUND.COM > DEBUG /???? "CSOUND.TXT"

Where do I drop this file, so you can get to it :?:


nitt
Posts: 218
Joined: 22 Apr 2011 02:43

Re: Is There A Quicker Way To Make The BEEP Sound In Batch?

#14 Post by nitt » 02 Jun 2011 08:34



CSOUND is a 16bit COM file. It doesn't work on my computer.

However, I did write a BEEP command in C++, so it doesn't use .NET framework like my others do. Ir lets you specify the frequency and the duration of the beep.

http://dl.dropbox.com/u/10434417/releases/commands/BEEP.exe

It's actually a very basic script. Here is all it took:

Code: Select all

#include <windows.h>
#include <iostream>
#include <fstream>

int main(int argcount,char* args[])
{
    if (args[1] != 0)
    {
    int freq = atoi(args[1]);
    int dur = atoi(args[2]);
    Beep(freq,dur);   
   

 if (args[1][0] == '/' && args[1][1] == '?')
    {
    std::cout << "\nPlays a BEEP with a specified duration and frequency.\n\nBEEP [frequency] [duration]\n\nExample: BEEP 1000 500\n";
    }
   
    }
    else
    {
        std::cout << "BEEP /? for help.\n";
        }
}


There's actually a Beep function in c++.

Post Reply