如何将程序打印定向到单独的窗口(shell/tty)

发布于 2024-09-15 17:11:27 字数 150 浏览 0 评论 0原文

我正在编写一个控制台应用程序,它使用一些启用(调试)打印的库。在我的 main() 应用程序中,我正在接受用户的输入。我希望此用户输入与我的图书馆打印分开。我无法禁用库调试打印。 (问题是库有大量连续打印,很难接受用户输入。我可以做一些事情,比如创建一个新的 tty 来接受用户输入。)

I am writing a console application which is using some library in which (DEBUG) prints are enabled. In my main() application I am taking inputs from user. I want this user input to be separate from my library prints. I cant disable library debug prints. (The problem is library has lots of continuous prints over which it is difficult to take user input. Can I do something like creating a new tty for taking user inputs. )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

递刀给你 2024-09-22 17:11:28

dup2(2,3p) 可让您将现有文件描述符(例如您刚刚在 /dev/null 上打开的文件描述符)复制到另一个现有文件描述符(例如 FD2) ,标准错误)。因此,打开 /dev/null 进行写入并用它破坏 stderr。

不要忘记添加一个选项来禁用此功能,以防您需要调试。

dup2(2,3p) lets you duplicate an existing file descriptor (such as the one you just opened on /dev/null) onto another existing file descriptor (such as FD2, stderr). So, open /dev/null for writing and clobber stderr with it.

Don't forget to add an option to disable this though, in case you need to debug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文