Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In MATLAB on Windows, cout is not sent to the Command Window #1612

Closed
chrisdembia opened this issue Mar 24, 2017 · 5 comments
Closed

In MATLAB on Windows, cout is not sent to the Command Window #1612

chrisdembia opened this issue Mar 24, 2017 · 5 comments
Labels

Comments

@chrisdembia
Copy link
Member

chrisdembia commented Mar 24, 2017

OpenSim methods often spew out useful text, but this text does not appear in the MATLAB Command Window; this behavior might surprise users. For example, calling Component::printOutputInfo() would logically display its output in the MATLAB Command Window, but the current behavior is that such output only appears in the out.log file.

This was noted by @carmichaelong and @nickbianco while working on the TGCS example.

From MATLAB Central (https://www.mathworks.com/matlabcentral/answers/102200-how-can-i-capture-stdout-of-a-generic-shared-library-method-called-from-matlab):

Anything printed to standard output (stdout) or standard error (stderr) is lost when a Windows program is running without a console.

Also, the behavior may depend on compatibility between the C runtime library used for MATLAB and OpenSim:

If the library is linked with (built with?) the same or a compatible version of the Microsoft C run-time libraries as MATLAB then you should not need this fix and stdout should be automatically redirected to MATLAB.

We can't rely on such compatibility, since we can't compile OpenSim separately for every possible version of MATLAB our users may have.

One workaround for TGCS is to tell users to just open the out.log file in MATLAB. This is what @carmichaelong has been doing.

Other relevant links:

@chrisdembia
Copy link
Member Author

@aymanhab does the GUI do anything special to get cout to print to the Messages pane in the GUI?

@aymanhab
Copy link
Member

@chrisdembia The GUI doesn't do anything special. I vaguely remember (from at least 10 yrs ago) that we created a logger to be accessed from both C++ and Java since streams were not portable cross language. If you look for "logger" you may find some clues if that code is still around 😕

@carmichaelong
Copy link
Member

On Windows, using a python IDE, output is also sent to out.log rather than command windows. Seen during advanced user workshop.

@chrisdembia
Copy link
Member Author

@nickbianco mentioned that the following code may help:

std::cout.rdbuf(LogManager::cout.rdbuf());
std::cerr.rdbuf(LogManager::cerr.rdbuf());

It's helped us in Moco (in C++; not tested in Matlab).

@aymanhab
Copy link
Member

This should be closed by the new logging feature (spdlog), any reason not to close, @chrisdembia, @nickbianco?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants