1
votes

I have a script that take some time to execute. I launch it in a C++ function, using Matlab Engine. To monitor the execution of the script, I wanted to add some disp('still alive') into it. However, it does not work, nothing is displayed into the matlab command window opened by engOpen (yes, I am sure the script is running, since I get output files at the execution end).

Any idea how I could get it to work ?

Beside, is it possible to get such heartbeats at script runtime, into the Windows command using engOutputBuffer ?

Thanks !

1

1 Answers

0
votes

Use engOutputBuffer, engEvalString and printf to get output to console (to Windows command window, not MATLAB command window).

If you want to monitor progress of your script, you can open m-script file in your C code and execute it command-by-command with engEvalString. After each executed command printf buffer contents to console window. The main problem in this approach is how to isolate (parse) commands in opened m-script file, but if you expect certain kind of scripts this can be done.

The other way you can achieve monitoring of messages is to open a thread after engOutputBuffer which will check content of the buffer and execute printf in parallel to execution of the m-script started in a main thread.

Check example at mathworks (near bottom of the page) on how to output MATLAB messages to console (Windows command).