开发者

Console for input commands

开发者 https://www.devze.com 2023-01-26 12:17 出处:网络
I want to make some debug console for my application. It shou开发者_运维知识库ld output some data and take input commands. How can I do this? The best way is updating console like: drawing information

I want to make some debug console for my application. It shou开发者_运维知识库ld 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.


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).
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号