question

Serge A avatar image
1 Like"
Serge A asked Phil BoBo commented

Redirect system console to file

Is there a way to redirect system console and output console messages to a file/files?

I have to debug a model where in a long-running Experiment some replications may randomly crash or get stuck. Unfortunately, these events are not reproducible (different replications may fail on a different Experiment Run). I'd like to see what was there in the system console just before the crash, to know what component/DLL to blame.

FlexSim 20.0.8
experimenterflexsim 20.0.8system consoledebugoutput console
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Serge A avatar image Serge A Joerg Vogel commented ·

Thank you for the answer @joerg.vogel but saving view text to file is not the same as redirecting console output to file. By redirection I mean that the output file is kept open all the time, and text is written to file as soon as it is printed to the console (or instead of). This is invaluable for debug, because if there is an exception dumped to the console, and then flexsim.exe crashes or enters an infinite loop, the last thing printed to the console will probably be saved. Custom event-triggered code may not get its chance to run at all before something bad happens, so saving view text to file is not only less efficient but it is also unreliable.

1 Like 1 ·

1 Answer

·
Phil BoBo avatar image
2 Likes"
Phil BoBo answered Phil BoBo commented

In a child experiment, the system console output is written to a std::stringstream. When the experiment finishes, the contents of the stringstream are written to a node and passed back to the parent.

You can get the text of the stringstream programmatically using applicationcommand("getconsoletext", 2), but as you noted, if the program is crashing or in an infinite loop, you don't have a callback opportunity to execute this function.

You might be able to get some crashing information if you add an exfslogfile.txt to your FlexSim documents directory and/or C:\exfslogfile.txt. There's old code in the engine that prints exceptions and crashing info to those files if they exist, but we haven't recently tested or used them to know whether they will be helpful or not.

· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Serge A avatar image Serge A commented ·

Thank you for the suggestion. I tried exfslogfile.txt, it may help, but probably won't. It seems to be overwritten by the last replication. And also registers only the first exception. So we're out of luck if any other replication crashes.

0 Likes 0 ·
1601377776700.png (90.5 KiB)
Phil BoBo avatar image Phil BoBo ♦♦ Serge A commented ·

If you put the file in both your documents and C: directory, then the one in the C: directory gets the full system console text instead of just the first exception.

It still only shows for the last replication though.

Maybe you can run the experiment with 1 Max Core and stop it once you get to the crashing replication?

There is code that creates new files with numbers appended, but that requires write permission on the root C: drive folder, which is difficult. (This code dates back to the Windows XP days when everything was run as administrator and everything had access to everywhere.)

1 Like 1 ·
1601395864019.png (284.7 KiB)

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.