MATLAB: Log file is not updating at first time execution of script

command windowdiary

Hello,
I am creating log file after the execution some command but for first time only file is creating not containing any log:
catch
disp("Error using slbuild_private:Unable to check out the Simulink Coder license to generate code")
diary('Error_log_file.txt');
In this case for the first time execution of script, is only creating 'Error_log_file.txt' and there is no log in it. But, when I am executing script second time and so on it's showing me log.
Is there any way to log command window data at 1st time of execution?
Thanks,

Best Answer

Invoke diary() before the disp()