In mex files, where does output to stdout and stderr go?
Mostra commenti meno recenti
If I link an external library to a mex file, and this library sends text output to stdout or stderr, what does MATLAB do with this output? Is there any way of saving it?
Risposte (3)
Oliver Woodford
il 12 Mag 2015
Modificato: Oliver Woodford
il 12 Mag 2015
Andrew Stevens
il 11 Feb 2018
Modificato: Andrew Stevens
il 11 Feb 2018
2 voti
Additionally to Olivers solution:
- In R2016 under Linux it would seem that mexPrintf itself uses iostream (internally). You have to switch the stream buffer back to the original for the mexPrintf call to avoid a stack overflow.
- In R2016 under Linux at least mexPrintf appears to check the thread from which it is being called (presumably because mx/mex API is not thread safe). If the calling stack is not the same as that used to enter mexFunction it merely logs "Error writing to output stream". The test (or is it a breakage?) alas is rather conservative: it triggers even if the "thread" is actually just a lightweight coroutine library like quickthreads is being used (e.g. SystemC).
The work-around is to buffer the output in the custom streambuf and flush only from the calling thread.
Tianyang Li
il 6 Gen 2015
1 voto
If you start maltab using -nojvm then stdout and stderr are visible.
1 Commento
A.B.
il 3 Apr 2020
This is the solution. Thanks for sharing.
Categorie
Scopri di più su MATLAB Compiler in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!