executing bluez functions in java

M

Mithil

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
 
J

Joshua Cranmer

Mithil said:
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.
 
M

Mithil

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
 
M

Mithil

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top