Closed GiovaGa closed 2 months ago
Here a simple code to bypass the logs:
import os
import sys
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Extend.DataExchange import write_step_file
def create_box():
# Create a simple box with dimensions 10x20x30
return BRepPrimAPI_MakeBox(10.0, 20.0, 30.0).Shape()
def execute_without_print(func, *args, **kwargs):
# Save original stdout and stderr
stdout_fd = sys.stdout.fileno()
stderr_fd = sys.stderr.fileno()
# Create a temporary file to capture the output
with open(os.devnull, 'w') as devnull:
# Redirect stdout and stderr to /dev/null
os.dup2(devnull.fileno(), stdout_fd)
os.dup2(devnull.fileno(), stderr_fd)
try:
# Execute the function
return func(*args, **kwargs)
finally:
# Restore stdout and stderr
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
# Example
box = create_box()
# Execute write_step_file without printing any messages
execute_without_print(write_step_file, box, "box.step")
print("STEP file has been written successfully.")
Not really what I was expecting, but it surely does what I need. I still think it could be useful to have a parameter in write_step_file (and probably other functions too) to disable logging.
Does depend on the OpenCascade C++ code? Otherwise I can try to contribute to this goal
Indeed, it depends on the C++ code
Ok, then I guess this issue can be closed. Thank you for the support
Is there any way to disable the following log:
It is printed every time I call
OCC.Extend.DataExchange.write_step_file
. As I am doing some batch jobs, it could hide some more useful messages.If it matters I am working on Windows 11 (64 bit).