Tried to execute command but not in whitelist (EXEC)?

That’s different. That’s not a whitelist error. That error just means the command called exited with an error code instead of exiting normally.

but I ran node "path.js" message in cmd and it gave me the decrypted text?

But you didn’t pass an encrypted message to the script, you passed it “hello” according to the log.

@rlkoshak for now it’s not doing anything with hello, it just returns a message. If this works I’d pass the encrypted msg I guess (i also passed hello in cmd and it returned a message, it’s not doing anything with hello for now)

Dumb question, but could the issue be something related to the commas? like how it is saying
[node, "C:\Users\username\OneDrive\Desktop\decrypt.js", hello]
instead of
node "C:\Users\username\OneDrive\Desktop\decrypt.js" hello
because the latter one is what I ran in cmd

So could it be that it’s running the command with the commas for some reason? Although there’s no commas in whitelist or mqtt transform…The first one kinda looks like an array could it be that the space separates the elements or am I thinking too much?

same error with a python script, which just returns uppercase, but logs are showing array like command

That’s just how it broke up the command into its parts. The first is the command and the rest are the arguments.

I is not running the command with the commas.

hmm…that’s weird. My script is just

import sys
inpt = sys.argv[1]
sys.stdout.write(inpt.upper())

in python, and when i do python filepath.py hello it simply returns HELLO in cmd…does exec want a different command?

I’m not seeing the logs. I don’t know the system. I don’t have the specific code/config that you are running right now with that python command. You are not mentioning what state the Item is in.

All I can say is that if you see the command broken up like that into an array in the logs, you no longer have a problem with the whitelist. If you don’t see an error log that means that the command ran successfully. If you do see an error, it’s hard to say whether or not the command ran successfully. It might have returned something meaningful but also returned an error code.

Does exec work like execute command line?

Depends on what you mean “work like”. executeCommandLine doesn’t require an entry in the white list. It can only be used in rules. You need to pass each argument to the command separately instead of as one string.

Is there any benefit to using MQTT transformation for incoming messages vs a rule that executes commabd line for item update? Would there be a difference in performance if there’s 1000 messages coming?

Frankly, attempting to processing thousands of messages a minute using Exec is likely to fail not matter what, especially if it’s doing something so CPU heavy as decryption. It’s a heavy lift to spin up a process for every message and I doubt anything but a really powerful machine will keep up.

Using a transformation at the binding will happen sooner since an event doesn’t need to be created and processed first. But ultimately, it’s going to take the same amount of processing no matter what.

ahh so I guess transformation at binding is the slightly better choice…but the command just isnt running although in cmd it runs fine :frowning:

I tried using execute command line but now it’s saying stuff like items isnt defined or execute command line isnt defined :(

It’s really hard to help without the actual code and configs you are running and the logs that are generated.

@rlkoshak

this is the python code

error is the same for js and python

Now Im trying to use execute command line in js automation (ecma2021) but this simple example:

items.getItem("decrypted").sendCommand(items.getItem("decipher").state); 

isnt even working i get this as error:

2022-06-28 11:59:34.060 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'D' failed: org.graalvm.polyglot.PolyglotException: ReferenceError: "items" is not defined

item isnt defined, also execute cmd line isnt defined when i try to use it

Also thanks a lot for continuing to help me with all this : )

I don’t care about the Python code. Frankly it’s irrelevant. I need:

The Thing, preferably the contents of code tab or the contents of the .things file.
The Profile if there is one (screen shot is about as good as you can get.
A little bit about the Item (e.g. the type and name).
The Rule, again preferably contents of the code tab or the full contents of the file the rule is defined in.
Exactly what states the Item is changing to (which can be found in events.log.

How is this rule triggered? How is this rule defined (file or UI)? That one line is not a complete rule. At best it might be part of a Script Action which is only part of a rule.

Did you change any of the JS Scripting settings under Settings in MainUI?

There are a ton of steps between an end device and an Item’s state and from there there can be a ton of steps to get through rules and display on the UI. Something can go wrong at any one of these stages.

Given that error, I’m not convinced that you’ve actually created a rule at all and have instead created a transformation or chose Rules DSL instead of ECMAScript 2021 or something. Seeing the full rule and other configs will instantly reveal the answer though.

You are jumping around all over the place, sometimes using Exec, other times using executeCommandLine, sometimes using a Profile and other times using the transformation and yet other times using a rule. It’s impossible to follow along and the meaning of the logs and errors and how to go about solving it.

@rlkoshak
Generic MQTT thing:

UID: mqtt:topic:lenovo:deff4055b0
label: Generic MQTT Thing
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: Offline
  payloadAvailable: Online
bridgeUID: mqtt:broker:lenovo
channels:
  - id: decipher
    channelTypeUID: mqtt:string
    label: decipher
    description: ""
    configuration:
      stateTopic: test

Profile is default

Items are all string. Decipher is one item that has the received msg, decrypted is another empty/placeholder item that’ll hold whatever sendCommand sends it.

Rule is:

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: decipher
    type: core.ItemStateUpdateTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript;version=ECMAScript-2021
      script: >-
        items.getItem("decrypted").sendCommand(items.getItem("decipher").state);
    type: script.ScriptAction

I used the UI to create this and selected ECMA2021 and wrote items.getItem("decrypted").sendCommand(items.getItem("decipher").state); to just see if it works, and if the value of decrypted is the same as decipher…but the error is in the previous comment

Goal: Ideally I would like to use this in rules/ecma2021 script:

        var plaintext=executeCommandLine("node","C:\Users\username\OneDrive\Desktop\decrypt.js", items.getItem("decipher").state);
        items.getItem("decrypted").sendCommand(plaintext); 

lmk if u need anything else, thanks!

I assume the cases match? It’s “decipher” not “Decipher” for the Item name?

Look in MainUI → Settings → JS Scripting and verify that “Use Built-in Variables” is selected. The only think I can think of that would cause items to not exist is if “Do Not Use Built-in Variables” is selected. See JavaScript Scripting - Automation | openHAB. You can import everything manually with var {Items} = require("openhab"); (I think that’s how to get Items when Built-in variables are not injected for you.

For the executeCommandLine, you need to pay attention to two different set of docs.

  1. How to call it (Actions | openHAB). Notice that only the version that takes a Duration as the first argument returns the results from the command.

  2. The JS Scripting reference docs for how to call executeCommandLine (JavaScript Scripting - Automation | openHAB).

You’ll see it looks a bit different than what you tried.

@rlkoshak yep, cases match. Built in variables was selected, unselected it and tried, and tried selected again, still not working. Do I have to uninstall and reinstall this add on maybe?

This is the error if I import manually:

[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'D' failed: org.graalvm.polyglot.PolyglotException: Java heap space

and yes I used both docs but none worked.

Tbh it’d be much better if the exec mqtt incoming msg transformation worked but it just wont execute commands :frowning: I have no idea why

@rlkoshak just to confirm, in my channel configuration for transformation i have

Is there a way to use execute command line here with exec? Is the command typed in the correct way to be executed correctly? Is this and the whitelist the only two places where the command needs to be?

OK, you have a very unhealthy openHAB instance. You are out of memory. What version are you running? 3.2 release and early 3.3. milestones have a memory leak that appeared most when you had rules that crashed.

You need to restart OH. If possible, upgrade to OH 3.3 release or later which has a fix for the memory leak.

As long as you are getting memory errors, you can’t trust anything your OH is doing.

No, it’s a rule action, only available in rules.

Have you tried giving it the full path to python or node? In general openHAB doesn’t get a full shell environment. What you have on the terminal may not be available to OH when it runs the command.

I’ve also seen weird stuff happen when trying to run scripts like this from OneDrive but that’s in an office environment so may not apply here.