Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

Exec cmd echo for beep with java on linux

Thread view: 
Nanou - 20 Oct 2005 17:49 GMT
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
Oliver Wong - 20 Oct 2005 19:03 GMT
> Hello,
>
[quoted text clipped - 9 lines]
> 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
Knute Johnson - 20 Oct 2005 19:32 GMT
> Hello,
>
[quoted text clipped - 9 lines]
> 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);
        }
    }
}

Signature

Knute Johnson
email s/nospam/knute/

Nanou - 21 Oct 2005 08:42 GMT
Thanks you very much, that's good for me.
Gordon Beaton - 20 Oct 2005 19:35 GMT
> 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

Signature

[  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

Dave Glasser - 20 Oct 2005 20:12 GMT
Gordon Beaton <not@for.email> wrote on 20 Oct 2005 20:35:14 +0200 in
comp.lang.java.programmer:

>> 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
[quoted text clipped - 9 lines]
>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().

Signature

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

Gordon Beaton - 20 Oct 2005 20:12 GMT
>   System.out.print('\0007');

Sorry! Should have been

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

/gordon

Signature

[  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

Roedy Green - 21 Oct 2005 02:34 GMT
>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.

Signature

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

Andrew Thompson - 21 Oct 2005 02:45 GMT
> 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/3aa4e
0abf416d49f/3df3fc271a3b9e4b?q=ping&rnum=1#3df3fc271a3b9e4b
>
Roedy Green - 21 Oct 2005 03:16 GMT
>> 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/3aa4e
0abf416d49f/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?

Signature

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

Pradyut - 21 Oct 2005 21:02 GMT
> Hello,
>
[quoted text clipped - 9 lines]
> Any help will be welcome.
> Thanks

I don't know about linux but under windows to execute we use

code1: -
----------------------------------------------
//import java.io.*;

public class RunExec
{
    public static void main(String args[])
    {
    String path="http://pradyut.tk";
    try
    {
        Process p = Runtime.getRuntime().exec("RunDLL32.EXE
shell32.dll,ShellExec_RunDLL " + path);
    }
    catch(Exception e )
    {
        System.err.println(e);
    }
    }
}
-------------------------------------------------------

code2: -
--------------------------------------------------------
public class RunExec1
{
    public static void main(String args[])
    {
    String path="http://pradyut.tk";
    try
    {
        Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler
http://yahoo.com" );
    }
    catch(Exception e )
    {
        System.err.println(e);
    }
    }
}
--------------------------------------------------------------

thanks

Pradyut
http://pradyut.tk
http://spaces.msn.com/members/oop-edge/
http://groups-beta.google.com/group/oop_programming
India
Pradyut - 21 Oct 2005 21:03 GMT
> Hello,
>
[quoted text clipped - 9 lines]
> Any help will be welcome.
> Thanks

I don't know about linux but under windows to execute we use

code1: -
----------------------------------------------
//import java.io.*;

public class RunExec
{
    public static void main(String args[])
    {
    String path="http://pradyut.tk";
    try
    {
        Process p = Runtime.getRuntime().exec("RunDLL32.EXE
shell32.dll,ShellExec_RunDLL " + path);
    }
    catch(Exception e )
    {
        System.err.println(e);
    }
    }
}
-------------------------------------------------------

code2: -
--------------------------------------------------------
public class RunExec1
{
    public static void main(String args[])
    {
    String path="http://pradyut.tk";
    try
    {
        Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler
http://yahoo.com" );
    }
    catch(Exception e )
    {
        System.err.println(e);
    }
    }
}
--------------------------------------------------------------

thanks

Pradyut
http://pradyut.tk
http://spaces.msn.com/members/oop-edge/
http://groups-beta.google.com/group/oop_programming
India


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.