Community discussions

 
tsafx
just joined
Topic Author
Posts: 3
Joined: Wed Mar 29, 2017 9:33 am

Strange behavior

Thu Jan 10, 2019 3:13 pm

Hello everyone!

If code run without ":delay 0.1" one of the variable doesn't set.
:execute ":global $ip [:pick \$$ipNet 0 [:find \$$ipNet \"/\" -1]]"
Any variables before and after this line set fine.
Only after added ":delay 0.1" the variable
:execute ":global $ip ..
set.

Maybe do anyone know why need ":delay" ?
:global getIpsettings do={
        :local int
	:if ([:len [/ip address find interface=$int1]]!=0) do={
		:set int $int1
	} else={
		:set int $int2
	}
	:local intName ($type . "Inteface")
	:execute ":global $intName $int"
	:local ipNet ($type . "IpNet")
	:execute ":global $ipNet [/ip address get [find interface=$int] address]"
        :delay 0.1
	:local ip ($type . "Ip")
	:execute ":global $ip [:pick \$$ipNet 0 [:find \$$ipNet \"/\" -1]]"
	:local net ($type . "Net")
	:execute ":global $net [/ip address get [find interface=$int] network]"
}
$getIpsettings int1=ether1 int2=ppp-out1 type=isp1
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1595
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: Strange behavior  [SOLVED]

Thu Jan 10, 2019 4:49 pm

:execute runs the command in separate thread. it's completion is not waited on. So the parameter configured by execute may not be set yet.
 
tsafx
just joined
Topic Author
Posts: 3
Joined: Wed Mar 29, 2017 9:33 am

Re: Strange behavior

Fri Jan 11, 2019 8:32 am

Sebastia, thanks a lot.

Who is online

Users browsing this forum: No registered users and 6 guests