File is created only after the second run of the script

Hi

Very simple ROS script:

:local filename "my.txt";
/file print file=$filename;
:local ff [/system routerboard get model];
/file set [find name=$filename] contents=$ff;

After the first start of script generated a file with the following contents:

# nov/ 4/2016  0:41:33 by RouterOS 6.36.4
# software id = PRPH-L49G
#
 # NAME                   TYPE                        SIZE CREATION-TIME       
 0 pub                    directory                        oct/30/2016 18:37:26

If it again to start the resulting file with the required content:

951Ui-2HnD

Tell me why we need two times to run to get the desired result ?

You can only write to a file once it exists, and the file doesn’t start existing for about 2 seconds after you make the call to create it.

So just :delay it, i.e.

:local filename "my.txt";
/file print file=$filename;
:local ff [/system routerboard get model];
:delay 2s;
/file set [find name=$filename] contents=$ff;

I already thought that I need to use a delay, but before that everything worked without it!