MQTT1 String with \\ double backward slash issue

Hi, Im trying to send a long string command through MQTT which requires double backward slash.

rule "Test String"

when Item Display_Run_String received update ON

logInfo("Running", "string")

Display_Run_Program_String.sendCommand ('{ "command" : "C:\\bat\\screensaver.bat", "args": "" , "path": "C:\\bat\\" , "user": "", "visible": false, "fallback": false }')


However it only sends single backward slash?

taken from mqttlens

Its difficult to read but this is what is received :
{ “command” : “C:\bat\screensaver.bat”, “args”: “” , “path”: “C:\bat” , “user”: “”, “visible”: false, “fallback”: false }

Is there something i need to do differently to allow this? Ive tried with writing three (3) backwardslashes but still only 1 is being sent.

Openhab 2.5 and mqtt1

Thank you and best regards

Since a single backslash () is used to indicate a special character (e.g \t is a tab character) you need to use two (\) to indicate you want a literal backslash. This, if you want two literal backslashes, each one needs to be escaped, so you would need four backslashes where you want two. Try:

Display_Run_Program_String.sendCommand ('{ "command" : "C:\\\\bat\\\\screensaver.bat", "args": "" , "path": "C:\\\\bat\\\\" , "user": "", "visible": false, "fallback": false }')

YOu can also try forwards slash. Many programming languages will accept forward slash even on windows.

That did the trick :slight_smile: learned something new, got the thing working. What a great way to end the day.

Thank you very much Anders

Best regards