Lua concatenation

Moderator: leecollings

Post Reply
tequila
Posts: 60
Joined: Tuesday 02 August 2016 17:08
Target OS: -
Domoticz version:
Contact:

Lua concatenation

Post 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.
Last edited by tequila on Tuesday 13 September 2016 18:21, edited 1 time in total.
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Lua concatenation

Post 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 :)
tequila
Posts: 60
Joined: Tuesday 02 August 2016 17:08
Target OS: -
Domoticz version:
Contact:

Re: Lua concatenation

Post 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.
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Lua concatenation

Post 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.
tequila
Posts: 60
Joined: Tuesday 02 August 2016 17:08
Target OS: -
Domoticz version:
Contact:

Re: Lua concatenation

Post 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...
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Lua concatenation

Post 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 :D
tequila
Posts: 60
Joined: Tuesday 02 August 2016 17:08
Target OS: -
Domoticz version:
Contact:

Re: Lua concatenation

Post by tequila »

haha, thanks for all the advices my friend. those quotes are quite confusing for me so I am glad it works now.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest