Forum

Author Topic: Suppress Console Output  (Read 1386 times)

MartinKobe

  • Newbie
  • *
  • Posts: 6
    • View Profile
Suppress Console Output
« on: May 16, 2024, 10:57:08 AM »
Dear Community,

we are executing some Metashape methods using the Python API.

As we are facing a large amount of console output:
Is there any way to suppress the console output somehow? (Maybe with redirection to a file?)

Best,
Martin


********************
Anyway, I found the following in the depth of the internet.
It generally works, but NOT with the Metashape module.


class suppress_stdout:
    def __enter__(self):
        self.old_stdout = sys.stdout
        sys.stdout = StringIO()  # Leerer Puffer für die Standardausgabe
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        sys.stdout = self.old_stdout
« Last Edit: May 16, 2024, 10:58:59 AM by MartinKobe »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15029
    • View Profile
Re: Suppress Console Output
« Reply #1 on: June 07, 2024, 01:13:22 PM »
Hello Martin,

do you run the script from Metashape GUI or from the OS terminal in headless mode? In the latter case you can redirect the output to file using common OS approach, for example:
Code: [Select]
./metashape.sh -r script.py > stdout.txt 2> stderr.txt
Best regards,
Alexey Pasumansky,
Agisoft LLC

MartinKobe

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Suppress Console Output
« Reply #2 on: June 17, 2024, 12:20:56 PM »
I run the script in a console within my spyder/pycharm IDE on a windows based system.

Is there also a possibility here to suppres output?