I’m not an expert, but I think the issue is that you are passing it as one string. Where there is whitespace separators in the string, all of the components either side of the whitespace have to be passed as separate parameters for it to work.
You are building and passing a single long string containing the whitespace separators, which I don’t think will work.
Based on the example you gave, there is no space in that part of the string, so I don’t think it needs breaking into separate parameters. If I’m correct, you only need to break where there are spaces (whitespace) in the command line.
Did you try it also without the timeout part?
The timeout should be used when you need the response from your execution.
Therefore the reponse has to be written into a variable.
Maybe thats already the reason for failing here.
If you just want to execute a script and it doesn’t matter what the reponse is, you should omit the duration parameter.
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.