Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - Exec cmd echo for beep with java on linux

 
Thread Tools Search this Thread
Old 10-20-2005, 05:49 PM   #1
Default Exec cmd echo for beep with java on linux


Hello,


I want to execute the command echo -e "\a" ( this command produce a
beep)from a java program whit Runtime.getRuntime().exec(); but it's
doesn't work. I don't heard the sound.
I can't use Toolkit.getDefaultToolkit().beep(); because under linux
this function have not effect.

OS: Mandriva Linux
JDK 1.5

Any help will be welcome.
Thanks



Nanou
  Reply With Quote
Old 10-20-2005, 07:03 PM   #2
Oliver Wong
 
Posts: n/a
Default Re: Exec cmd echo for beep with java on linux
"Nanou" <> wrote in message
news: oups.com...
> Hello,
>
>
> I want to execute the command echo -e "\a" ( this command produce a
> beep)from a java program whit Runtime.getRuntime().exec(); but it's
> doesn't work. I don't heard the sound.
> I can't use Toolkit.getDefaultToolkit().beep(); because under linux
> this function have not effect.
>
> OS: Mandriva Linux
> JDK 1.5
>
> Any help will be welcome.
> Thanks


If it's absolutely a mission critical requirement that a beep be
produced, then you'll have to ship custom hardware with your product. I have
a few computers, for example, with no speakers on them at all (not even the
"PC Speaker" normally attached to a motherboard), so it doesn't matter what
code you write in what language: no beep will be generated on these
machines.

If it isn't that essential, then maybe you shouldn't worry too much
about beeps not being produced under some architectures using
"Toolkit.getDefaultToolkit().beep()".

- Oliver




Oliver Wong
  Reply With Quote
Old 10-20-2005, 07:32 PM   #3
Knute Johnson
 
Posts: n/a
Default Re: Exec cmd echo for beep with java on linux
Nanou wrote:
> Hello,
>
>
> I want to execute the command echo -e "\a" ( this command produce a
> beep)from a java program whit Runtime.getRuntime().exec(); but it's
> doesn't work. I don't heard the sound.
> I can't use Toolkit.getDefaultToolkit().beep(); because under linux
> this function have not effect.
>
> OS: Mandriva Linux
> JDK 1.5
>
> Any help will be welcome.
> Thanks
>


This should do what you need.

knute...

import javax.sound.sampled.*;

public class Tone {
public static void sound(int hz,int msecs) throws
LineUnavailableException {
byte[] buf = new byte[msecs*8];

for (int i=0; i<buf.length; i++) {
double angle = i / (8000.0 / hz) * 2.0 * Math.PI;
buf[i] = (byte)(Math.sin(angle) * 80.0);
}

AudioFormat af = new AudioFormat(8000f,8,1,true,false);
SourceDataLine sdl = AudioSystem.getSourceDataLine(af);
sdl.open(af);
sdl.start();
sdl.write(buf,0,buf.length);
sdl.drain();
sdl.close();
}

public static void main(String[] args) {
try {
Tone.sound(2000,150);
} catch (LineUnavailableException lue) {
System.out.println(lue);
}
}
}

--

Knute Johnson
email s/nospam/knute/


Knute Johnson
  Reply With Quote
Old 10-20-2005, 07:35 PM   #4
Gordon Beaton
 
Posts: n/a
Default Re: Exec cmd echo for beep with java on linux
On 20 Oct 2005 09:49:51 -0700, Nanou wrote:
> I want to execute the command echo -e "\a" ( this command produce a
> beep)from a java program whit Runtime.getRuntime().exec(); but it's
> doesn't work. I don't heard the sound.


All it does is print the character value 7 to the terminal, which
interprets the character and rings the bell.

You can do it directly from Java like this:

System.out.print('\0007');

Whether or not this actually creates any sound depends on your
terminal.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e


Gordon Beaton
  Reply With Quote
Old 10-20-2005, 08:12 PM   #5
Dave Glasser
 
Posts: n/a
Default Re: Exec cmd echo for beep with java on linux
Gordon Beaton <> wrote on 20 Oct 2005 20:35:14 +0200 in
comp.lang.java.programmer:

>On 20 Oct 2005 09:49:51 -0700, Nanou wrote:
>> I want to execute the command echo -e "\a" ( this command produce a
>> beep)from a java program whit Runtime.getRuntime().exec(); but it's
>> doesn't work. I don't heard the sound.

>
>All it does is print the character value 7 to the terminal, which
>interprets the character and rings the bell.
>
>You can do it directly from Java like this:
>
> System.out.print('\0007');
>
>Whether or not this actually creates any sound depends on your
>terminal.


And furthermore, Nanou, the reason you didn't hear the beep with
Runtime.getRuntime().exec() is that the STDOUT stream of the exec'ed
process is captured, rather than sent to the console. You can read it
with the InputStream returned by Process.getInputStream(). That's why
stuff like redirect characters (">" and ">>") or pipes on the command
line don't work as expected with Runtime.exec().


--
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.

http://qform.sourceforge.net

If you're a musician, check out RPitch Relative Pitch
Ear Training Software.

http://rpitch.sourceforge.net


Dave Glasser
  Reply With Quote
Old 10-20-2005, 08:12 PM   #6
Gordon Beaton
 
Posts: n/a
Default Re: Exec cmd echo for beep with java on linux
On 20 Oct 2005 20:35:14 +0200, Gordon Beaton wrote:
> System.out.print('\0007');


Sorry! Should have been

System.out.print('\u0007');

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e


Gordon Beaton
  Reply With Quote
Old 10-21-2005, 02:34 AM   #7
Roedy Green
 
Posts: n/a
Default What the beep
On 20 Oct 2005 09:49:51 -0700, "Nanou" <> wrote
or quoted :

>I want to execute the command echo -e "\a" ( this command produce a
>beep)from a java program whit Runtime.getRuntime().exec(); but it's
>doesn't work. I don't heard the sound.
>I can't use Toolkit.getDefaultToolkit().beep(); because under linux
>this function have not effect.


there is one more thing easier to try. see
http://mindprod.com/jgloss/beep.html

See http://mindprod.com/jgloss/exec.html
if that does not work. Echo may be an internal command. If it is you
will need to spawn a command interperter.

Shade of Monty Python and the machine that goes beep.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.


Roedy Green
  Reply With Quote
Old 10-21-2005, 02:45 AM   #8
Andrew Thompson
 
Posts: n/a
Default Re: What the beep
Roedy Green wrote:

> Shade of Monty Python and the machine that goes beep.


I dare say you are becoming confused between the threads/quotes.

Ping?
<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/3aa4e0abf416d49f/3df3fc271a3b9e4b?q=ping&rnum=1#3df3fc271a3b9e4b>


Andrew Thompson
  Reply With Quote
Old 10-21-2005, 03:16 AM   #9
Roedy Green
 
Posts: n/a
Default Re: What the beep
On Fri, 21 Oct 2005 01:45:48 GMT, Andrew Thompson
<> wrote or quoted :

>> Shade of Monty Python and the machine that goes beep.

>
>I dare say you are becoming confused between the threads/quotes.
>
>Ping?
><http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/3aa4e0abf416d49f/3df3fc271a3b9e4b?q=ping&rnum=1#3df3fc271a3b9e4b>


If this exchange is sailing over your head, you probably have not yet
seen the classic Monty Python movie, the Meaning of Life.

Some dialog from it is quoted here:
http://sfy.ru/sfy.html?script=mp_meanlife
More apparatus please, nurse.
And, uh, get the machine that goes 'ping'.


That leads to the slightly OT discussion. You can't do a true ping in
Java, but can you in Python?


--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.


Roedy Green
  Reply With Quote
Old 10-21-2005, 08:42 AM   #10
Nanou
 
Posts: n/a
Default Re: Exec cmd echo for beep with java on linux
Thanks you very much, that's good for me.



Nanou
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
What Is Linux? Andrew.Robinson.group.com@gmail.com DVD Video 0 12-31-2007 03:06 PM
Suse Linux and Red Hat Linux Raymond A+ Certification 3 07-16-2004 01:41 AM
Re: Dual booting W2K and Linux on TWO HDs Tom MacIntyre A+ Certification 0 08-06-2003 11:29 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46