'send a message to slack using curl in a lua script
I get an error with this script when trying to send a message to slack using curl in LUA. Thanks for your help.
cmd="c:\\curl\\bin\\curl.exe -X POST -H "Content-type: application/json" -d "{\"text\":\"Hello\"}" https://hooks.slack.com/services/xxxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxx"
LUA_ERROR:[string "cmd="c:\curl\bin\curl.exe -X POST -H "Content-type: applicat..."]:1: =' expected near -'
Solution 1:[1]
Your script is full of syntax errors because you didn't bother to escape the double quotes enclosing the arguments of your cURL command. The simplest solution is to just use long strings here, which don't require you to escape double quotes while not interpreting \" as ", thus preserving your inner escapes:
cmd=[[c:\curl\bin\curl.exe -X POST -H "Content-type: application/json" -d "{\"text\":\"Hello\"}" https://hooks.slack.com/services/xxxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxx]]
alternatively you could use single quotes, requiring you to escape all backslashes:
cmd='c:\\curl\\bin\\curl.exe -X POST -H "Content-type: application/json" -d "{\\"text\\":\\"Hello\\"}" https://hooks.slack.com/services/xxxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxx'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | LMD |
