As some of us already have discovered, execution of external executable by popen() may not hold Lua script to wait until external processing has been completed. But sometimes we want it to be synchronized with Lua script flow.
To resolve this requirement we can use lock file in conjunction with ‘&&’ operator ( ‘&&’ operator applicable to Windows only. WIth *nix OS we will use only lock file.)
local convert = io.popen( 'c:\\executable.exe '.. Argument1..' '..ArgumentN..' && touch 'c:\\lockfile.done') end local i=0 while not os.fs.access('c:\\lockfile.done') and i < 1500 do util.sleep(3) i = i+1 end local Success = io.popen("del /f ".."c:\\lockfile.done")
The '&&' operator actually does error check and if previous command (execution of executable.exe) failed for any reason, then it will not allow to create control lock file on disk (the 'touch' command will not be executed).
A counter to wrap sleep() function, is being used to prevent script from waiting for lock file for longer than say 4.5 seconds (3 X 1500 = 4500 msec).
A bunch of Log entries can be added, and some additional logic can be created based upon testing values of 'convert' and existence of lock file.
You must be logged in to reply to this topic.