Exec binding - syntax?

Dear Community,

I have a USB controlled relay setup. It is responding to hex commands, I’ve tested and is working fine from the shell, I just can not get it work with exec.
Here is my simple rule:

rule “Turn the light on”
Item Living_Room received command ON
val result=executeCommandLine(“echo -en ‘\xA0\x01\x01\xA2’ > /dev/ttyUSB0”, 1000)
logInfo(“exectest”, “Command line result: {}”, result)

I have run it with and without debug logging:

020-04-28 23:09:22.353 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘default.rules’
2020-04-28 23:09:25.897 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine ‘echo -en ‘\xA0\x01\x01\xA2’ > /dev/ttyUSB0’

2020-04-28 23:13:45.295 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘default.rules’
2020-04-28 23:13:47.260 [INFO ] [ipse.smarthome.model.script.exectest] - Command line result: �� > /dev/ttyUSB0

Based on the characters before > /dev/ttyUSB0 I suppose it is some kind of syntax error.

Do you have any suggestions for it?

Thank you in advance!

Try putting the commands in a shell script and running that.
The exec binding has no shell and command redirection is usually a shell function.

1 Like

Thank you!

That worked!


1 Like