How to start a system “beep”, from the built-in pc speaker, using a batch file?

前端 未结 7 1217
悲&欢浪女
悲&欢浪女 2020-12-08 16:59

I have written a batch script in an interactive mode, for making some tasks.

Sometimes, These tasks takes a long time to be finished, and then the batch asks if the

7条回答
  •  一个人的身影
    2020-12-08 17:34

    The following can be used to issue a beep

    • without pausing the script
    • without creating a new line.
    • without requiring the use of a non-printable character
     Echo/| CHOICE /N 2> nul & rem BEL
    

    It is a deliberate misuse of the choice command, that Echo's nothing via a pipe to Choice, causing a non-breaking error. STDERR is redirected to nul, and the default choice prompt is suppressed via the /N switch, meaning no new line is output.

    If for some reason you wanted to reuse this annoying tone throughout a script, you could define it as a macro

    Set "BEL=Echo/| CHOICE /N 2> nul"
    %BEL%
    

提交回复
热议问题