With executeCommandLine you can only start one program with arguments.
Starting multiple programs (with redirection and pipes) is a function of a command shell.
or you “simply” create a shell skript with the complete command inside. chmod, that the user openhab can execute the script. After that just call the script in the rule (only a example):
I’m struggling with this too. The problem is that the script I want to execute takes a variable number of arguments that are determined at runtime, so splitting them up like executeCommandLine("python", "/home/openhab/myscript.py", arg1, arg2, ...) is not an option. Replacing spaces with @ or @@ as often recommended doesn’t work either. Spaces were not a problem back in OH2’s executeCommandLine().
Why does this issue even exist? What is the purpose of splitting up arguments? Please just let me pass a string directly to bash or whatever like any other exec function out there does. That would also solve all problems that users have with piping etc at once.
Encapsulate your call to python in a shell scirpt ( as long as you do not have dynamic arguments ).
Replacing spaces with @s does not work in OH3 afaik.
That’s only required if you want to process the output.
I meant those to be variables. But this style of passing arguments isn’t useful for me anyway because I have a string with an arbitrary number of spaces.
That’s the problem.
That’s because of how Java’s Varargs work. If a method accepts an arbitrary number of arguments, they always need to be at the very end.
However, that’s also the solution! I just found out it’s possible to pass an array instead of individual arguments:
val cmnd = "python /home/openhab/myscript.py " + myarguments
executeCommandLine(cmnd.split(" "))
You can’t mix both however, so executeCommandLine("python", "/home/openhab/myscript.py", myarguments.split(" ")) will not work.