I am try to use executeCommandLine curl

I have no experience with executeCommandLine and curl
And I’m asking the experienced guys here how I can execute this command:

rule "test rule"

when

 Item testbutton changed 

then

         executeCommandLine("curl-d '{"id":"test", "action":"activate"}' -H 'Content-Type: application/json' -X PUT http://192.168.0.111:8888/api/scenes")

end

First, I’d recommend not using this and instead use sendHttpPutRequest instead. Even better would be to use the HTTP Binding if what you are really trying to have happen is to send a PUT request when a Switch Item is toggled.

But if you continue to use executeCommandLine, please review the docs so you pass the right arguments to it in the right way.

Also, be careful with your Strings. Look at the code highlighting above. Notice how it’s not all highlighted the same color. That means that it’s not one big String but instead a series of Strings (red) and stuff that is not a String(black).

Every time you have a " that starts a new String until the next " is seen. Therefore you can’t have a naked " inside a String that starts with " because that will essentially end the String. So you have to escape it so that it’s treated as part of the String, not as the end of the String. The same rule applies for '. Given this rule you have:

Part Type
curl -d '{ String
id ???
: String
test ???
, String
action ???

and so on.

You need a single string so you need to escape all those ``` and " that are part of the String using \.

"curl -d \'{\"id\":\"test\", ....

Thank you for the response but I have already found a solution
See here:
[SOLVED] I cant run simple sh script - Off-Topic - openHAB Community

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.