输入命令的控制台

发布于 2024-10-03 13:17:56 字数 127 浏览 5 评论 0原文

我想为我的应用程序制作一些调试控制台。它应该输出一些数据并接受输入命令。我该怎么做?最好的方法是更新控制台,例如:绘制信息并在数据后提示输入。 我是在Linux下开发的。例如,gdb 可以从控制台获取输入。

I want to make some debug console for my application. It should output some data and take input commands. How can I do this? The best way is updating console like: drawing information and prompt for input after the data.
I'm developing under Linux. For example, gdb could take input from console.

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

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

发布评论

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

评论(1

等风也等你 2024-10-10 13:17:56

如果您熟悉套接字编程(或者实际上任何其他类型的 IPC 机制),您可能希望在应用程序中启用一些侦听器,并开发一个外部应用程序,该应用程序将在通信时为您完成所有“控制台”工作与主要应用程序。

假设您有一个具有单个按钮和单个文本标签的应用程序,每次按下该按钮时,文本标签都会增加 1,从 1 到 2 到 3 等。

您可以在该应用程序中构建一个套接字侦听器。当套接字侦听器接受新的传入连接时,您将启动一个连接线程,该连接线程可以:

  1. 接收“关闭”命令
  2. 接收“重置计数器”命令
  3. 的更新
  4. 发送有关每次单击的当前计数等

。然后您构建另一个,外部应用程序,连接到主应用程序,并根据从用户那里获得的控制台输入向其发送消息。它还会监听传入的更新并将其显示给用户。

使用外部应用程序来调试控制您的主应用程序非常有帮助,其优点如下:

  1. 无论调试应用程序有多么错误,它都不会损害主应用程序的发布版本。
  2. 所有处理控制台管理的代码(对于主应用程序来说是多余的)都可以保留在主应用程序之外。
  3. 只要你们都了解双方之间的协议,用它制作两个项目可以让您更轻松地与其他人协作工作。
  4. 实施我的建议意味着您可以远程调试应用程序,以防您无法访问主应用程序(例如,如果它位于客户站点上)。

If you're familiar with socket programming (or actually, any other kind of IPC mechanism), you might want to enable some listener within your application, and develop an external application that will do all the "console" stuff for you, while communicating with the main application.

Let's suppose you have an application that has a single button and a single text label, and every time you press that button - the text label goes up by 1, from 1 to 2 to 3 etc.

You can build a socket listener into that application. When the socket listener accepts a new incoming connection, you'd start a connection thread that can:

  1. Receive a "shutdown" command
  2. Receive a "reset counter" command
  3. Send an update regarding the current count on every click
  4. etc.

Then you build another, external application, which connects to the main application, and sends messages to it, based on console input it gets from the user. It would also listen to incoming updates and show them to the user.

Using an external application for debug-controlling your main application is extremely helpful, with the following reasons being some of the advantages:

  1. No matter how the debug application is buggy, it cannot hurt the release version of your main application.
  2. All the code that deals with the console management, which is redundant to your main application, can be kept outside of the main app.
  3. Making two projects out of it can make it easier to collaborate your work with someone else, as long as you are both aware of the protocol between the two sides.
  4. Implementing what I suggested means you can debug your application remotely, in case you don't have access to the main application (for example, if it's on a customer site).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文