Redirect console output to string #42
-
Hi, Is there anything I can do to either caputre the complete console output or to redirect it to a file so I can read it afterwards? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi, Sonnet tries to hand a wrapped MessageHandler to the underlying coin-or C++ libraries, for example when reading Mps files to get the underlying message over to System.Console, but this isn't working for much of the CbcSolver output, which is why your Console.SetOut isn't capturing it, unfortunately. I haven't been able to figure out how to pass more message to the Sonnet MessageHandler--you can use A completely different way to combine all output is to use the Process class and Process.StandardOutput, but this requires that your Sonnet code is in a separate executable from your main application. Lastly, if what you're trying to do is keep progress, then you could rather use some of the Cbc (or Clp etc.) EventHandlers that are called every time a new solution is found, etc. See Sonnet_CbcTests for examples of how to inject handlers from Sonnet. Or, similarly, the CbcSolver CallBack. Hope this help? |
Beta Was this translation helpful? Give feedback.
-
Great!
SonnetLog writes to System.Console, so SonnetLog output you can read using Console.SetOut. Does that work for you? (But, again, not all cbc message are nicely passed to the SonnetLog message handler..) |
Beta Was this translation helpful? Give feedback.
Hi,
Sonnet is a .NET (Framework) library, but the actual solving is done in the coin-or libraries like Cbc etc. in SonnetWrapper.
Sonnet itself outputs to the regular System.Console of .NET.
However, the underlying coin-or C++ libraries like Cbc use (s)printf etc. via message handlers to output, e.g. in CbcSolver.cpp. This output from (s)printf is not going to System.Console by itself.
Sonnet tries to hand a wrapped MessageHandler to the underlying coin-or C++ libraries, for example when reading Mps files to get the underlying message over to System.Console, but this isn't working for much of the CbcSolver output, which is why your Console.SetOut isn't capturing it, unfortunately. I haven…