I have the following test rule:
rule “Dateiinhalt an Telegram senden”
when
Item Switch_Admin_Test received update // Schalter 'Switch_Admin_Test' betätigt wird
then
val filePath = "/openhab/conf/import/Losungen_2023.txt" // Pfad zur Datei
val message = executeCommandLine("cat "+ filePath) // Dateiinhalt auslesen
// Überprüfen, ob der Dateiinhalt erfolgreich ausgelesen wurde
if (message !== null && message.trim() !== "") {
telegramAction.sendTelegram("Dateiinhalt: " + message) // Telegram-Nachricht senden
} else {
logError("Rule", "Fehler beim Auslesen der Datei.") // Fehlermeldung, falls das Auslesen fehlschlägt
}
end
VisualCode shows me the following Messag: "Type mismatch: type void is not applicable at this location"
In the log I get: java.io.IOException: Cannot run program "cat /openhab/conf/import/Losungen_2023.txt": error=2, No such file or directory
yes, the file exists.
Within the container there is no prob for this “command line”.
executeCommandLine(String commandLine) : Executes a command on the command line without waiting for the command to complete.
If it doesn’t wait, it obviously cannot return the result of the command.
executeCommandLine(Duration.ofSeconds(timeout), String commandLine) : Executes a command on the command and waits timeout seconds for the command to complete, returning the output from the command as a String.
Without a timeout, executeCommandLine doesn’t return anything (i.e. void).
Be careful with that. When you run something manually inside the container you are running as user root. However, openHAB is running as some other user (uid 1000 by default). You have to be careful about user permissions when testing commands like that by using su openhab or su 1000 first. sudo does not exist in the container.