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 / April 2007

Tip: Looking for answers? Try searching our database.

executing bluez functions in java

Thread view: 
Mithil - 11 Apr 2007 14:59 GMT
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
Joshua Cranmer - 11 Apr 2007 22:25 GMT
> Hi everyone,
>
[quoted text clipped - 17 lines]
>        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.
Mithil - 12 Apr 2007 10:55 GMT
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 - 12 Apr 2007 16:05 GMT
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


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



©2008 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.