Creating log file for Matlab compiler's created executable

10 次查看(过去 30 天)
Hi I am using matlab compiler to compile an application. I want to create a logfile when its executed. Everything works fine, and logfile is created and information from the Matlab command prompt is added to it as well. What if I want to use a variable logfile name, such as using current date and time as a part of the filename. To be specific, I want to use:
datestr(clock,30)
as a part of the name so that a filename such as:
mylogfile_20170428T101532.log
is created. The way to create fixed name logfile at run time is to specify it at the compile time:
mcc -R '-logfile, filename.log' ..........
Using strcat options for variable filename such as:
mcc -R strcat('''-logfile,DotCodeReader_',datestr(clock,30),'.log''')
Don't work. I don't want to use the diary option of creating a logfile since diary created logfile appears empty until the executable is stopped.
Any suggestions, please?
Best Regards
Wajahat

回答(2 个)

Prannay Jain
Prannay Jain 2017-5-1
You probably cannot provide the variable in the logfile name while using 'mcc'. As a workaround, create an expression of the mcc command where you use the filename variable and call this expression in eval.
>> filename = ['mylogfile_', datestr(clock,30), '.log']
>> exp = ['mcc -m test.m', ' -R ''-logfile,', filename, '''']
>> eval(exp);
  2 个评论
Walter Roberson
Walter Roberson 2017-5-1
That cannot help relative to the option of using mcc as a function passing in variables like Wajahat Kazmi showed.
Wajahat Kazmi
Wajahat Kazmi 2017-5-3
编辑:Wajahat Kazmi 2017-5-3
Thanks. It does work, however, the point of using the variable name is that the compiled EXE should generate a new name of the logfile, every time it is executed. With the above solution using eval, the filename gets pre-defined. So this is not desired.

请先登录,再进行评论。


Jan
Jan 2017-5-1
Do you mean:
filename = ['mylogfile_', datestr(clock,30), '.log'];
mcc('-R', '-logfile', filename)
?
  2 个评论
Wajahat Kazmi
Wajahat Kazmi 2017-5-1
编辑:Wajahat Kazmi 2017-5-3
Hi Jan Yes. Thanks a lot for your suggestion. But it says '-a' is not used:
filename = ['mylogfile_', datestr(clock,30), '.log'];
mcc ('-R', '-logfile',filename, '-m', '-o', 'myoutputexec', 'mymatlabcode.m')
Error: You specified the file "mylogfile_20170501T215900.log" without using the "-a" option.
Whereas, '-a' option includes an already existing file in the compilation. Besides, the filename creating should be a part of the mcc command line so that every time the compiled executable is run, it should generate a new logfile with date and time of creation a part of it. Even some random number would also work. The point is that re-running the executable should not over write the previous log file, which, unless the name is changed, it does.
Wajahat Kazmi
Wajahat Kazmi 2017-5-3
Using the following:
strcat('-logfile,', 'mylogfile_', datestr(clock,30), '.log')
in the mcc function call does work, but again, it fixes the logfile name to the date and time when the executable was generated.
mcc ('-R', strcat('-logfile,', 'mylogfile_', datestr(clock,30), '.log') '-m', '-o', 'myoutputexec', 'mymatlabcode.m')
The question remains, as to how to get the executable call either:
datestr(clock,30)
or even a random number generator instead to generate a new sequence of characters to the logfile name every time the exe is run.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 C Shared Library Integration 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by