我想用Java扫描Rasberry Pi上的BLE设备。 我使用了posted BLE scanning script (ibeacon_scan.sh)中的answer of jjnebeker。当我在UNIX笔记本电脑上使用以下Java代码启动它时,它的效果非常好:
public void init(String[] commands){
// commands -> {"/bin/bash","-c","/<PATH>/ibeacon_scan.sh"}
ProcessBuilder processBuilder = new ProcessBuilder(commands);
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
createAndStartProcessOutputHandlerThread(process);
}
private Thread createAndStartProcessOutputHandlerThread(Process process) {
Thread thread = new Thread(new Runnable() {
public void run() {
Scanner scan = null;
try {
scan = new Scanner(process.getInputStream());
while (true) {
if(scan.hasNext()){
String line = scan.nextLine();
LOG.info("LINE: ", line);
}
}
} finally {
if(scan != null) {
scan.close();
}
}
});
thread.start();
return thread;
}
我在Rasberry Pi上将脚本作为sudo启动,我只得到空行 但没有其他信息作为例外或其他:(
编辑: 当我在Rasberry Pi上的shell中执行脚本时,脚本正确运行。
我不知道如何解决这个问题。 你能帮帮我吗?