0

I am writing a program (a GUI for easy control of several instruments at once) in Python that has a lot of dependencies. When I run it, one of the functions that I call produces several lines of output to the terminal:

[USB.DLL] - t_dev_open(0xffb50000) - ENTRY
[USB DLL] - t_dev_open() - d->num_channels:4
[USB.DLL] - t_dev_open(0xffb00000) - ENTRY
[USB DLL] - t_dev_open() - d->num_channels:4
[USB.DLL] - t_dev_open(0xffba0000) - ENTRY
[USB DLL] - t_dev_open() - d->num_channels:4

This is annoying, since the program is for others to use and I only want them to see output that is part of the user interface. I know exactly which function call in my code triggers it, but I have no details about what goes on under the hood. The library involved is the Thorlabs Scientific Camera SDK, which is mostly DLLs (although there is no USB.dll that I can find, which would have been my first guess based on the output). The function is TLCameraSDK.open_camera().
My question is, is there a way to easily trace this output and find out where it comes from? I'm on a windows machine using CMD, although if a Linux shell would be helpful I have access to that as well. Any answer that includes ideas for suppressing output from a .dll would be extra helpful, although that's probably for a separate question (I'll ask it once I've pinpointed the source).

aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • What is annoying? That you see the terminal? – d6stringer Aug 18 '21 at 18:56
  • @d6stringer No, the terminal is going to be there regardless. It's the 6 lines of output that get printed that the user doesn't need to see. – Brendan Mitchell Aug 18 '21 at 19:37
  • 1
    Does this answer your question? [Capture stdout from a script?](https://stackoverflow.com/questions/5136611/capture-stdout-from-a-script) in particular: https://docs.python.org/3.5/library/contextlib.html#contextlib.redirect_stdout – Zev Aug 18 '21 at 21:25
  • @Zev Afraid not, unless I'm missing something. The output isn't being sent to stdout. I tried wrapping the function call in a redirect_sdtout context manager as the link suggests (along with a print statement to make sure it's working) and the output still comes through. – Brendan Mitchell Aug 18 '21 at 22:38
  • Hmmm... maybe this one? https://stackoverflow.com/a/57677370/1830793 – Zev Aug 18 '21 at 23:20
  • Actually, for suppressing dll output, this works well (although it causes a native Windows error if I try to print() anything within the context manager; see [this question](https://stackoverflow.com/questions/66784941)). Thanks for the tip! I'd still like to find an answer to the original question, about finding the actual source of the output. – Brendan Mitchell Aug 26 '21 at 17:37

0 Answers0