0

I'd like my java program to make a Windows machine beep when the program is run. Typing ^G (Control-G) in the command prompt causes a beep sound.

Is there a way to use Runtime's exec() to pass a control character to the command prompt?

e.g. runtime.exec(CONTROL_G); // hmm

CS Student
  • 1,543
  • 4
  • 21
  • 34
  • Possible [duplicate](http://stackoverflow.com/q/10771441/230513). – trashgod Sep 08 '15 at 15:40
  • 1
    Possible [duplicate](http://stackoverflow.com/q/2064066/230513). – trashgod Sep 08 '15 at 15:41
  • @nLee unfortuantely that answer doesn't solve my problem. Since exec() expects a string I can't simply send the number 7 :( – CS Student Sep 08 '15 at 16:10
  • @CSStudent if all you want is a beep, see the question trashgod linked; otherwise, you could use the answer nLee linked - use a ProcessExecutor to run "cmd.exe", and write the command code to stdout. – Sbodd Sep 08 '15 at 16:52

1 Answers1

0

It depends what environment you are in, but on Windows using Cygwin, I use the following:

String.valueOf((char) 27) which is the escape character, followed by the control character

nLee
  • 1,230
  • 2
  • 10
  • 20