Remember that publicVariable handlers are only run remotely, not locally, so you need to do a bit more to ensure your code runs globally (both remotely and locally).
To do what you asked for is an entirely generic system to run code:
global_command_handler = { call compile _this };
"global_command" addPublicVariableEventHandler { (_this select 1) call global_command_handler };
global_command = "[flag, Lgate, Rgate, 0, 3] exec ""log\scripted_gate.sqs""";
publicVariable "global_command"; // Run remotely.
global_command call global_command_handler; // Run locally.
However, what you should probably do in this case, assuming you really have to use sqs, is:
open_gate_handler = { _this exec "log\scripted_gate.sqs" };
"open_gate" addPublicVariableEventHandler { (_this select 1) call open_gate_handler };
open_gate = [flag, Lgate, Rgate, 0, 3];
publicVariable "open_gate"; // Run remotely.
open_gate call open_gate_handler; // Run locally.