Hi,
I’m trying the new Exec binding but it won’t work for me. I’m using Build #614 (Debian package openhab2-online 2.0.0~20161126032927
).
system.items
String System_OpenFiles "Anzahl offener Dateien" { channel="exec:command:open_files:output" }
system.things
Thing exec:command:open_files [ command="sudo /usr/bin/lsof -u openhab |wc -l", interval=5, timeout=3 ]
Log output
2016-11-27 13:50:57.651 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occured while reading the stderrwhen executing 'sudo /usr/bin/lsof -u openhab |wc -l' : 'Stream closed'
I think this is en error in the binding. Looking at the source code at https://github.com/openhab/openhab2-addons/blob/8d5af21df40440f018a17bfd392ce4b3376a0df5/addons/binding/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/handler/ExecHandler.java, I think at line 143 it should read proc.getOutputStream()
instead of proc.getErrorStream()
.
try (InputStreamReader isr = new InputStreamReader(proc.getErrorStream());
// ^^^^^^^^^^^^^^
BufferedReader br = new BufferedReader(isr);) {
String line = null;
while ((line = br.readLine()) != null) {
outputBuilder.append(line).append("\n");
logger.debug("Exec [{}]: '{}'", "OUTPUT", line);
}
isr.close();
} catch (IOException e) {
logger.error("An exception occured while reading the stdout when executing '{}' : '{}'",
new Object[] { commandLine.toString(), e.getMessage() });
}
Please let me know if my thinking is right.
Thanks,
Aaron