Page 1 of 1
Lua concatenation
Posted: Tuesday 13 September 2016 18:21
by tequila
Going crazy already...
Any idea why this doesn't work?
devIP="X.X.X.X"
devPort="XXX"
commandArray={}
if os.execute('nc -n -w 1 ".. devIP.." ".. devPort .. "') and...
While this works just fine?
commandArray={}
if os.execute('nc -n -w 1 X.X.X.X XXX') and...
Can't figure out what the issue is.
Re: Lua concatenation
Posted: Tuesday 13 September 2016 22:12
by Nautilus
Something like this:
if os.execute('nc -n -w 1 '..devIP..' '..devPort) and...
?
to see how lua / domoticz interprets it you can also add:
print('nc -n -w 1 '..devIP..' '..devPort)
and check the log to see if the printed command makes any sense

Re: Lua concatenation
Posted: Wednesday 14 September 2016 7:18
by tequila
I actually did print the command and it looks as expected in the log.
I tried to play with single and double quotes too, but still no luck.
Re: Lua concatenation
Posted: Wednesday 14 September 2016 10:28
by Nautilus
Hmm, strange. In the first example of yours, I don't think you can add a variable as part of the command and use a different type of quote than the one with which the command begins. So when you start with single, then you need to use single to tell the interpreter that text ends there and a variable comes next (with ..). Again same should be applied to continuing with text again. Inside the single quotes you could have the double quotes as well 8and they'd print as part of the command), but in this case not needed.
Re: Lua concatenation
Posted: Tuesday 20 September 2016 11:02
by tequila
tried once again and this seems to finally work:
devIP='X.X.X.X'
devPort='XXX'
commandArray={}
if os.execute("nc -n -w 1 ".. devIP.." ".. devPort .. "") and...
Re: Lua concatenation
Posted: Tuesday 20 September 2016 22:55
by Nautilus
tequila wrote:tried once again and this seems to finally work:
devIP='X.X.X.X'
devPort='XXX'
commandArray={}
if os.execute("nc -n -w 1 ".. devIP.." ".. devPort .. "") and...
Good that it works

Essentially I think the above is the same as I had my first reply (well, I had single quotes but it shouldn't play any role):
Code: Select all
os.execute('nc -n -w 1 '..devIP..' '..devPort) and...
Except that you also have the ending quotes. Though I'd think they are not needed because a variable is ending the command so it is not adding anything. But it is not the first time something works differently from what I assume

Re: Lua concatenation
Posted: Wednesday 21 September 2016 11:03
by tequila
haha, thanks for all the advices my friend. those quotes are quite confusing for me so I am glad it works now.