OH3 JS Scripting execCommandline return value is NULL

OH3.4.1 on openHABian.

I’m using JS Scripting to execute a Bash-Script, which returns a string.

....
var exec = actions.Exec.executeCommandLine("/etc/openhab/scripts/quickchart.sh", param1, param2);
console.log(exec);
....

returns:

2023-01-13 13:55:33.681 [INFO ] [nhab.automation.script.ui.TibberCalc] - null

The return of the script looks like this:

openhabian@openHABMain:/etc/openhab/scripts $ sudo -u openhab ./quickchart.sh 17,16,17,18 19,20,21,22,24
TibberChart_20230113-135533.png

So, I would expect the exec to have the value “TibberChart_20230113-135533.png”

How can I fill the exec variable with the output of the Bash-Script?

If the command takes any time to run, then you need to give the action a timeout duration so it waits for the return value:

1 Like

Even if the command doesn’t take any time to run, without the Duration executeCommandLine will not return the output of the command.

@binderth this leads us to the same place. If you care what the output of the command called is, you must supply a Duration.

1 Like

Thanks both for the input! Did this with DSL rules, didn’t know that JS Scripting does it, too - but obviously it does! :smiling_face:

I know that’s how the baseline action works, but that is inconsistent with what is in the library docs:

// Get response from command line.
var response = actions.Exec.executeCommandLine(‘echo’, ‘Hello World!’);

// Get response from command line with timeout.
response = actions.Exec.executeCommandLine(Duration.ofSeconds(20), ‘echo’, ‘Hello World!’);

so (without checking the actual code, I admit) I had assumed that the helper library is passing an additional default duration when none is provided.

Hmmm. We should be consistent. Looking at the code, it’s actually a direct call on the Java org.openhab.core.model.script.actions.Exec Class so it is the same as Rules DSL and all the rest. The JS Scripting docs are wrong. I’ll file a PR to fix that right now.

2 Likes