executing bluez functions in java

Discussion in 'Java' started by Mithil, Apr 11, 2007.

  1. Mithil

    Mithil Guest

    Hi everyone,

    I am trying to schedule a script which runs a java file and that java
    file executes a bluez linux command called hciconfig -i hci0 scan
    which scans for bluetooth devices but i get an error in the cron log
    file which is :

    /home/mithil/t: line 2: clear: command not found
    java.io.IOException: Cannot run program "hcitool":
    java.io.IOException: error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
    at java.lang.Runtime.exec(Runtime.java:593)
    at java.lang.Runtime.exec(Runtime.java:431)
    at java.lang.Runtime.exec(Runtime.java:328)
    at test.main(test.java:6)
    Caused by: java.io.IOException: java.io.IOException: error=2, No such
    file or directory
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
    at java.lang.ProcessImpl.start(ProcessImpl.java:65)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
    ... 4 more

    Cron is not able to recognize the bluez command. I had the same
    problem with executing java files in cron but I added the path to java
    file at the top of the cronfile and it works but couldn't figure out
    how to get the bluez command working could some one please help me
    out.

    the java program is :

    public class test {
    public static void main(String[] args) {
    try {
    Process startUP = Runtime.getRuntime().exec("hcitool -i
    hci0 scan");
    Process scan = Runtime.getRuntime().exec("hcitool -i hci0
    scan");
    BufferedReader in = new BufferedReader(
    new
    InputStreamReader(scan.getInputStream()));
    String line = null;
    while ((line = in.readLine()) != null) {
    System.out.println(line);
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }

    The script is:
    |!/bin/sh
    java test

    The cronfile is:
    PATH=$PATH:/home/mithil/jdk1.6.0_01/jre/bin
    * * * * * /home/mithil/t > /home/mithil/cronlog.txt 2>&l
    Mithil, Apr 11, 2007
    #1
    1. Advertising

  2. Mithil wrote:
    > Hi everyone,
    >
    > I am trying to schedule a script which runs a java file and that java
    > file executes a bluez linux command called hciconfig -i hci0 scan
    > which scans for bluetooth devices but i get an error in the cron log
    > file which is :
    >
    > /home/mithil/t: line 2: clear: command not found
    > java.io.IOException: Cannot run program "hcitool":
    > java.io.IOException: error=2, No such file or directory
    > at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
    > at java.lang.Runtime.exec(Runtime.java:593)
    > at java.lang.Runtime.exec(Runtime.java:431)
    > at java.lang.Runtime.exec(Runtime.java:328)
    > at test.main(test.java:6)
    > Caused by: java.io.IOException: java.io.IOException: error=2, No such
    > file or directory
    > at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
    > at java.lang.ProcessImpl.start(ProcessImpl.java:65)
    > at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
    > ... 4 more


    The problem is obvious: Java can't find the program "hcitool", so try
    giving a full path to hcitool.
    Joshua Cranmer, Apr 11, 2007
    #2
    1. Advertising

  3. Mithil

    Mithil Guest

    hi Joshua,

    Thanks for the reply, I think I have allready tried what you are
    asking me to do. I included the path PATH=$PATH:/etc/bluetooth but if
    I do that it is not recognizing java or the normal linux fucntions
    like ls for some reason. The cronfile of this would look like this:

    PATH=$PATH:/home/mithil/jdk1.6.0_01/jre/bin
    PATH=$PATH:/etc/bluetooth
    * * * * * /home/mithil/t > /home/mithil/cronlog.txt 2>&l

    Thanks again,
    Mithil
    Mithil, Apr 12, 2007
    #3
  4. Mithil

    Mithil Guest

    hi Joshua,

    It works for me now I could find the path using whatis hcitool command
    and then include the path in the java file when i am trying to execute
    the hcitool command like this:

    Process startUP = Runtime.getRuntime().exec("/usr/bin/hcitool -i hci0
    scan");

    and it works !!! thanks for your help
    Mithil, Apr 12, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmFzIE1hbmdoZXJh?=

    ASP.NET not executing interop functions

    =?Utf-8?B?SmFzIE1hbmdoZXJh?=, Apr 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    441
    =?Utf-8?B?SmFzIE1hbmdoZXJh?=
    Apr 6, 2005
  2. Xiangliang Meng
    Replies:
    1
    Views:
    1,568
    Victor Bazarov
    Jun 21, 2004
  3. Kaiser S.
    Replies:
    3
    Views:
    958
  4. Shadow123
    Replies:
    0
    Views:
    278
    Shadow123
    Aug 11, 2008
  5. Isaac
    Replies:
    0
    Views:
    297
    Isaac
    Mar 3, 2010
Loading...

Share This Page