Quantcast
Channel: MikroTik
Viewing all articles
Browse latest Browse all 21118

Scripting • Passing a parameter from a script to another script

$
0
0
Hello everybody! This is not GPT! My question is: I want to pass a parameter from one script to another. What's easier, you say, do it through global variables. But I want to do without variables (the interest is purely academic)

I managed to do it using this method:

script Transfer:
Code:
:local scrName "scriptReceiver":local Var1 "Par1=mytext":local Var2 "Par2=12":execute script="[[:parse \"[:parse [/system script get $scrName source]] $Var1 $Var2\"]]"
script Receiver:
Code:
:log warning "$Par1 $Par2":log warning [:typeof $Par1]:log warning [:typeof $Par2]:local Par3 [:tonum $Par2]:log error $Par3:log error [:typeof $Par3]
In the design :execute script="[[:parse \"[:parse [/system script get $scrName source]] $Var1 $Var2\"]]"
:execute is clearly redundant, it is enough [[:parse \"[:parse [/system script get $scrName source]] $Var1 $Var2\"]]

From my experience, it can be seen that

1. all parameters are passed as string parameters and after catching them, the receiver script must convert their type back, knowing it in advance.
2. And secondly, strings can only be transmitted in Latin. I was unable to pass string parameters in the national language (say Cyrillic).

Questions:

1. Is there any way to do this more gracefully? (without global variables and functions).
2. And is it possible to somehow pass parameters with their types (not only in string form) and pass the Cyrillic alphabet? I tried to transfer Cyrillic alphabet in HEX format like \D0\E1, etc... - it doesn't work.

Statistics: Posted by Sertik — Mon Dec 04, 2023 11:10 am



Viewing all articles
Browse latest Browse all 21118

Trending Articles