Reputation: 198
I'm writing Python script in photogrammetry application Metashape. App is written in C/C++ and I would like to suppress all of its console output and make my own progress bar. There are several solutions proposed on how to suppress C++ prints within Python script, but all of those are based on an idea of getting file descriptor of standard output (sys.stdout
). Python within Metashape
is probably edited and built by Metashape's
developers team so some functionalities are missing. There is no method fileno()
in sys.stdout
so I cannot get this file descriptor. I suppose I could hard code it, but this script if just a part of a bigger architecture and a lot of files are imported, exported and edited, so I suppose this is not a very good idea. This is probably the most promising solution I've find link, but I am stuck at the beginning of it. Any ideas?
Edit:
Python version: 3.5.2 (default, Aug 28 2018, 15:41:10) [MSC v.1600 64 bit (AMD64)]
Note that in the script there are more than twenty C++ function calls that produce massive console output, so it would be ideal to make it possible to block and re-enable C++ output during the process. Also, any simpler solution, even if you ignore problem with non existing method fileno()
, would be appreciated. There should be simpler solution to suppress C++ output within Python app
Upvotes: 0
Views: 1624
Reputation: 11
You can access to console pane through Metashape.app.ConsolePane
class or can just allow to create log file with Metashape.app.settings.log_enable = True
and Metashape.app.settings.log_path = '...\log.txt'
check the doc here: Metashape python API doc.
However you can also try to use solution described here: How do I prevent a C shared library to print on stdout in python? I just tested it on my stand alone Metashape python script and works really well. Metashape python api v. 1.6.5, Python v. 3.7.9
Upvotes: 1